Authentication

Set up the authentication for your API to help users manage their credentials.

Log in to see your API keys
API KeyLabelLast Used

Nector authenticates every request with an API key. Depending on where the call is made from, a customer scoped request may additionally need to prove which customer it acts for. Generate API keys and the signing secret from the dashboard under Settings > API Keys.

Headers on Every Request

HeaderRequiredDescription
x-apikeyYesYour Nector API key.
x-workspaceidYesYour Nector workspace id.
x-sourceYesOrigin of the request: web (browsers and servers) or mobile (native apps).
x-leadtokenStorefront keys onlyThe lead token of the customer on customer scoped APIs.

API Key Types

KeyWhere to use itWhat it can do
Write accessYour backend onlyEverything. Required for Create User, Create Wallet Transaction, Create Credit Wallet Transaction, Reward Offer, Reward Cross Selling Offer and Reward Using Trigger for triggers that are not marked open. No customer authentication is needed since your backend is trusted.
Read only, purpose serverYour backendAll GET APIs and customer facing writes such as Reward Using Trigger for open triggers, Redeem Offer, Checkout Redemption and Create Review. No customer authentication is needed.
Read only, purpose storefrontYour web or mobile appSame APIs as the server read only key, but customer scoped APIs need the customer to be authenticated with a lead token in x-leadtoken, so that a visitor cannot act on another customer's account.
❗️

Keep write access keys on your backend

Never expose a write access API key in a browser or app. Use read only keys wherever possible.

Storefront Keys and the Lead Token

When a request comes from a browser or app, the customer id cannot be trusted. A storefront read only key therefore requires x-leadtoken on every customer scoped API. The lead token is a JWT that identifies one customer and is valid for 1 hour. When it is passed, the customer is taken from the token and any lead_id or customer_id in the request is ignored.

There are two ways to obtain a lead token. Both need your API signing secret, so both run on your server.

Option A: Generate the Token on Your Server

If your server already knows the Nector lead _id of the customer, sign the token yourself.

JWT payload: { "lead_id": "<nector-lead-id>" }
Algorithm:   HS256
Secret:      <api-signing-secret>
Expiry:      1 hour

Send the token to your storefront and pass it as x-leadtoken on every customer scoped request.

Option B: Exchange a Digest for a Token with Get User

If your storefront only knows your own customer id (for example a Shopify customer id), compute a short lived digest on your server and call Get User with it. This is the only API that accepts a digest.

Step 1: Compute the digest on your server

timestamp = current unix time in seconds
digest    = hex( HMAC-SHA256( "<customer-id>:<timestamp>", <api-signing-secret> ) )

A platform prefix on the customer id, one of shopify-, woocommerce-, magento- or custom_website-, is stripped before computing the digest. For customer_id shopify-12345 sign 12345:<timestamp>.

Step 2: Call Get User with the digest

The path id can be any placeholder UUID v4, the customer_id query parameter takes precedence.

curl "https://cachefront.nector.io/api/v2/merchant/leads/<any-uuidv4>?customer_id=shopify-12345" \
  -H "x-apikey: <storefront-read-only-api-key>" \
  -H "x-workspaceid: <your-workspace-id>" \
  -H "x-source: web" \
  -H "x-timestamp: <timestamp>" \
  -H "x-leaddigest: <digest>"
📘

x-timestamp is required with x-leaddigest and must be within 60 minutes of the server time.

Step 3: Use the lead token

Read data.lead_token from the response and pass it as x-leadtoken on all other customer scoped requests. The response also carries the wallet, tier and membership of the customer, so no extra call is needed.

Which Lead Credential Each API Accepts

APIAccepted with a storefront key
Get Userx-leaddigest or x-leadtoken
All other customer scoped APIsx-leadtoken only

Security Notes

  • Compute digests and lead tokens on your server only. Never ship the signing secret to a browser or app.
  • Lead tokens expire after 1 hour, so refresh them for long sessions.
  • Get User masks email and mobile in the response. When looked up by email, mobile or referral code with a read only key, it also omits _id, customer_id, wallet_id and creditwallet_id so that a visitor cannot discover another customer's ids.
  • If origin IPs are configured on an API key, requests must come from those IPs.
Credentials
LoadingLoading…
Response
Click Try It! to start a request and see the response here!

Did this page help you?