Skip to content
Cartly Developers

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

  1. Go to your store admin → Settings → API Keys
  2. Click “Create API Key”
  3. Name it, select permission scopes, set expiry
  4. Copy the key immediately — it is shown only once

Using the Key

bashAuthenticate with API key
curl -H "Authorization: Bearer ck_live_abc123..." \
     -H "Content-Type: application/json" \
     https://cartly.pro/apps/api/products

An 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

FeatureAPI KeyOAuth 2.0
SetupInstantApp registration + redirect
Best forScripts, internal toolsThird-party apps
Token refreshNot neededRequired (1h expiry)
RevocationSettings → API KeysApp management

Authentication Methods

Public API

No Auth

No authentication required. Used for storefront data like products, collections, and search.

Session Cookie

Cookie

Browser-based sessions for customer accounts. Login, orders, addresses, and wishlists.

JWT Token

Bearer

JSON Web Tokens for merchant admin API access. Used by the admin dashboard.

OAuth 2.0

OAuth

Authorization 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:

  1. Redirect the merchant to /oauth/authorize with your client ID, scopes (space-separated), redirect URI, state and a PKCE code_challenge.
  2. Merchant approves the requested permissions in the Cartly admin.
  3. Cartly redirects back to your redirect_uri with an authorization code.
  4. 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.

httpRedirect merchant to Cartly
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=S256

Step 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:

bashExchange code for tokens
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 header
  • refresh_token — use this to get new access tokens
  • expires_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.

httpInstall handoff request
GET https://your-app.com/cartly/install
  ?shop=my-shop.mycartly.pro
  &shop_id=7c1e…
  &install_id=0f9a…
  &timestamp=1767225600
  &hmac=4b1f…
  • shop: the shop's storefront host
  • shop_id: the shop's ID
  • install_id: the marketplace install's ID
  • timestamp: when Cartly signed the request (Unix seconds)
  • hmac: hex HMAC-SHA256, keyed with your client_secret, of all the other parameters sorted by name and joined as name=value&name=value (decoded values)

Verify the hmac with a constant-time comparison, and reject a stale timestamp before you trust the parameters:

javascriptVerify the install request
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.

ScopeDescription
products:readView products and variants
products:writeCreate, update, and delete products
orders:readView orders and order history
orders:writeUpdate order status and fulfillment
orders:ownView only orders created by this app
customers:readView customer information
customers:writeCreate and update customers
discounts:readView discount codes and rules
discounts:writeCreate, update, and delete discounts
metafields:readView custom metafields
metafields:writeCreate, update, and delete metafields
webhooks:manageManage webhook subscriptions
shop:readView shop settings and configuration
collections:readView product collections
collections:writeCreate, update, and delete collections
shipping:readView shipping zones and rates
shipping:writeManage shipping configuration
analytics:readView analytics and reports
inventory:readView inventory levels
inventory:writeSet inventory levels (PUT /apps/api/inventory/:variant_id)
theme_extensions:writeAdd app blocks that render on the storefront (OAuth apps only)
checkout_extensions:writeAdd 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.

bashRefresh access token
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

javascriptFetch products with OAuth token
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