Authentication
Cartly supports multiple authentication methods depending on your integration type.
Overview
Cartly provides four authentication methods, each designed for different use cases. Choose the method that best fits your integration.
API Keys (Simple Authentication)
For direct REST API access without the OAuth flow, create an API key in your admin panel. This is the fastest way to start making authenticated API calls.
Creating a Key
- Go to your store admin → Settings → API Keys
- Click “Create API Key”
- Name it, select permission scopes, set expiry
- Copy the key immediately — it is shown only once
Using the Key
curl -H "Authorization: Bearer ck_live_abc123..." \
-H "Content-Type: application/json" \
https://cartly.pro/apps/api/productsAn API key works on the Apps API (/apps/api/*) only, within its scopes. The merchant admin API (/admin/*) refuses API keys with 403.
API Keys vs OAuth
| Feature | API Key | OAuth 2.0 |
|---|---|---|
| Setup | Instant | App registration + redirect |
| Best for | Scripts, internal tools | Third-party apps |
| Token refresh | Not needed | Required (1h expiry) |
| Revocation | Settings → API Keys | App management |
Authentication Methods
Public API
No AuthNo authentication required. Used for storefront data like products, collections, and search.
Session Cookie
CookieBrowser-based sessions for customer accounts. Login, orders, addresses, and wishlists.
JWT Token
BearerJSON Web Tokens for merchant admin API access. Used by the admin dashboard.
OAuth 2.0
OAuthAuthorization code flow for third-party apps. Granular scopes and token refresh.
OAuth 2.0 Authorization Code Flow
For third-party apps, Cartly uses the OAuth 2.0 Authorization Code flow. Here is how it works:
- Redirect the merchant to
/oauth/authorizewith your client ID, scopes (space-separated), redirect URI,stateand a PKCEcode_challenge. - Merchant approves the requested permissions in the Cartly admin.
- Cartly redirects back to your
redirect_uriwith an authorizationcode. - Exchange the code for an access token and refresh token via a server-side POST request.
Step 1: Authorization Request
PKCE is required. Generate a random code_verifier (43–128 characters), keep it server-side, and send code_challenge = base64url(SHA-256(code_verifier)), without = padding, with code_challenge_method=S256 (plain is refused at the exchange). A request without it is rejected.
Scopes are space-separated. Names Cartly doesn't know are dropped. Request only scopes registered for your app: a mismatch makes the merchant's approval fail (the consent page shows an error) and your redirect_uri gets no callback.
GET https://cartly.pro/oauth/authorize
?response_type=code
&client_id=your_client_id
&redirect_uri=https://your-app.com/callback
&scope=products:read%20orders:read
&state=random_csrf_token
&code_challenge=BASE64URL_SHA256_OF_CODE_VERIFIER
&code_challenge_method=S256Step 2: Token Exchange
After the merchant approves, they are redirected to your callback URL with a code parameter. Exchange it for tokens, sending the code_verifier from step 1:
curl -X POST "https://cartly.pro/oauth/token" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "authorization_code",
"code": "AUTH_CODE_FROM_CALLBACK",
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"redirect_uri": "https://your-app.com/callback",
"code_verifier": "the_code_verifier_from_step_1"
}'The response contains:
access_token— use this in the Authorization headerrefresh_token— use this to get new access tokensexpires_in— token lifetime in seconds (default: 3600)scope— granted scopes (may differ from requested)
Marketplace Install
When a merchant installs your app from the Cartly marketplace, Cartly sends them to the Install URL you set in your app settings (https, no query string). Cartly cannot start OAuth for you, because it never has your PKCE code_verifier. Your app starts the flow instead. An app without an Install URL is installed, and the merchant connects it from your own site.
GET https://your-app.com/cartly/install
?shop=my-shop.mycartly.pro
&shop_id=7c1e…
&install_id=0f9a…
×tamp=1767225600
&hmac=4b1f…shop: the shop's storefront hostshop_id: the shop's IDinstall_id: the marketplace install's IDtimestamp: when Cartly signed the request (Unix seconds)hmac: hex HMAC-SHA256, keyed with yourclient_secret, of all the other parameters sorted by name and joined asname=value&name=value(decoded values)
Verify the hmac with a constant-time comparison, and reject a stale timestamp before you trust the parameters:
import crypto from "node:crypto";
// query = the parsed query of the install request (URLSearchParams)
function verifyInstall(query, clientSecret) {
const hmac = query.get("hmac") ?? "";
const message = [...query.entries()]
.filter(([key]) => key !== "hmac")
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([key, value]) => `${key}=${value}`)
.join("&");
const expected = crypto.createHmac("sha256", clientSecret).update(message).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(query.get("timestamp"))) < 300;
return fresh && hmac.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(hmac), Buffer.from(expected));
}Then start the authorization request above with your own state and PKCE code_challenge. You can also forward install_id to /oauth/authorize. The consent page then offers only the shop the app was installed on. Cartly refuses the authorization if the ID is not your app's install on that shop.
Scopes
Scopes control what your app can access. Request only the scopes you need.
| Scope | Description |
|---|---|
products:read | View products and variants |
products:write | Create, update, and delete products |
orders:read | View orders and order history |
orders:write | Update order status and fulfillment |
orders:own | View only orders created by this app |
customers:read | View customer information |
customers:write | Create and update customers |
discounts:read | View discount codes and rules |
discounts:write | Create, update, and delete discounts |
metafields:read | View custom metafields |
metafields:write | Create, update, and delete metafields |
webhooks:manage | Manage webhook subscriptions |
shop:read | View shop settings and configuration |
collections:read | View product collections |
collections:write | Create, update, and delete collections |
shipping:read | View shipping zones and rates |
shipping:write | Manage shipping configuration |
analytics:read | View analytics and reports |
inventory:read | View inventory levels |
inventory:write | Set inventory levels (PUT /apps/api/inventory/:variant_id) |
theme_extensions:write | Add app blocks that render on the storefront (OAuth apps only) |
checkout_extensions:write | Add extensions that render during checkout (OAuth apps only) |
Token Refresh
Access tokens expire after 1 hour. Use the refresh token to get a new access token without requiring the merchant to re-authorize. Refresh tokens rotate: the response carries a new refresh_token — store it, the old one is revoked.
curl -X POST "https://cartly.pro/oauth/token" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "refresh_token",
"refresh_token": "your_refresh_token",
"client_id": "your_client_id",
"client_secret": "your_client_secret"
}'Code Examples
JavaScript / Node.js
const response = await fetch("https://cartly.pro/apps/api/products", {
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data.data); // products; paging in data.meta