API clients & authentication
Every API request carries an OAuth 2.0 access token. Your own systems get tokens from a private client using the client credentials grant. Third-party apps such as Zapier and Make use the authorization code grant with PKCE.
In short
- An API client is a key for one of your systems. Create it under Settings → Developers → Private clients.
- Exchange its client ID and secret at
/oauth/tokenfor an access token that lasts one hour. - The client secret is shown only once. Copy it when you create the client.
Before you start#
- Access to the CXS Loyalty app in your Shopify admin.
- A list of what your system needs to do, so you can pick only those permissions.
- A safe place to store the client secret, such as a secret store.
Create a private client#
A private client lets one of your own systems get API tokens for this store, with only the permissions you pick.
- In the app, go to Settings → Developers.
- On the Private clients card, click Create private client.
- Enter a Name (up to 80 characters). Only you see it, so name it after the system that uses it.
- Under Permissions, pick at least one permission (see the table below).
- Click Create. The Copy your client secret window shows the Client ID and Client secret.
- Copy both and store them somewhere safe, then click Done.
This is the only time the secret is shown. If it’s lost or leaked, open the client and click Generate new secret.
You can have up to 10 private clients. Create one for each system that uses the API, so you can switch them off separately. Client IDs start with cxl_pc_ and secrets with cxl_cs_.
Permissions (scopes)#
| Scope | Label in the app | Allows |
|---|---|---|
read:customers |
See loyalty members and their balances | List and get customers, with status, balance and tier |
write:customers |
Enroll customers in the loyalty program | Enrol Shopify customers in the program |
read:points |
See points balances | Read point balances |
write:points |
Add and remove points | Points adjustments |
read:activities |
See points activity | Read point history |
read:rewards |
See rewards | Read rewards and redemptions |
write:redemptions |
Redeem rewards for customers | Redeem rewards (also lists a customer’s redemptions) |
read:tiers |
See VIP tiers | Read VIP tiers and customers’ progress |
read:referrals |
See referrals | Read referral links and referrals |
manage:webhooks |
Receive loyalty events | Create, list, test and delete webhook endpoints |
The API reference lists the scope each endpoint needs.
Get an access token#
Send the client ID and secret to the token endpoint with grant_type=client_credentials. You can authenticate in either of two ways:
- HTTP Basic auth (
client_secret_basic). client_idandclient_secretin the form body (client_secret_post).
curl -X POST "https://loyalty-program.cxsnippets.com/oauth/token" \
-u "cxl_pc_YOUR_CLIENT_ID:cxl_cs_YOUR_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials"
{
"access_token": "cxl_at_…",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "read:customers read:points write:points"
}
- Lifetime: access tokens last one hour. Private clients get no refresh token. Request a new token when the old one expires.
- Scopes: leave out
scopeto get every permission the client has. To ask for fewer, sendscopeas a space-separated list, for example--data-urlencode "scope=read:customers read:points". Asking for a scope the client doesn’t have is refused. - Using it: send
Authorization: Bearer cxl_at_…on every API call. - Checking it:
GET /public/v1/meshows the store, the client, the scopes the token holds andtoken_expires_at.
The server publishes its OAuth metadata (RFC 8414) at https://loyalty-program.cxsnippets.com/.well-known/oauth-authorization-server.
Manage, rotate or revoke a client#
Open Settings → Developers → Manage private clients. The list shows each client’s Client ID, Permissions and Last token. Click Manage on a client to:
- Change permissions: taking a permission away also stops the client’s current tokens.
- Switch it off: turn off Active. The client can’t get tokens, and the ones it has stop working.
- Generate new secret: the current secret and every token issued with it stop working at once. Update your system with the new secret.
- Delete client: the client and its tokens stop working at once. This can’t be undone.
Your system can also revoke a single token itself (RFC 7009). A client can only revoke its own tokens.
curl -X POST "https://loyalty-program.cxsnippets.com/oauth/revoke" \
-u "cxl_pc_YOUR_CLIENT_ID:cxl_cs_YOUR_CLIENT_SECRET" \
-d "token=cxl_at_…"
Third-party apps#
Apps that connect to many stores, such as Zapier and Make, use the authorization code grant with PKCE (S256). The endpoints are /oauth/authorize and /oauth/token. Add shop=<store>.myshopify.com to skip the store question.
- A staff member approves the connection on a consent page inside the Shopify admin. The page lists what the app will be able to do. The staff member clicks Allow or Deny.
- Access tokens last one hour. Refresh tokens are replaced on every use. A connection left unused for 90 days expires.
- Connected apps appear under Settings → Developers → Connected apps, where a merchant can Disconnect them. The app loses access right away.
Third-party apps must be registered with us before they can connect. If you’re building an app for many stores, contact CXS support at support@cxsnippets.com.