Skip to content
New Webhooks added: Inventory and Order modifications. Check the changelog →
Cartly Developers

Authentication

Learn about Cartly's authentication methods: Public API, Session, JWT, and OAuth 2.0.

Authentication Methods

MethodUse CaseAuth Header
Public (none)Storefront API — products, collections, searchX-Shop-ID: {shop_id}
Session CookieCustomer accounts — orders, addresses, wishlist__session cookie
JWT BearerAdmin panel — product management, order processingAuthorization: Bearer {token}
OAuth 2.0Third-party apps — marketplace integrationsAuthorization: Bearer {access_token}

OAuth 2.0 Flow

Cartly implements the standard Authorization Code flow per RFC 6749:

  1. Register your app — Create an OAuth app in the Cartly admin with redirect URIs and requested scopes
  2. Authorization request — Redirect merchant to /oauth/authorize with a PKCE code_challenge (S256, required)
  3. User consent — Merchant approves requested permissions
  4. Token exchange — Exchange authorization code for access + refresh tokens
  5. API access — Use access token in Bearer header

Rules worth knowing

  • PKCE — code_challenge = base64url(SHA-256(code_verifier)) without = padding, code_challenge_method=S256; plain is refused at the token exchange.
  • Scopes — space-separated. Names Cartly doesn't know are dropped. Request only scopes registered for your app: a registered-scope mismatch makes the merchant's approval fail (the consent page shows an error) and your redirect_uri gets no callback.
  • Refresh tokens rotate — each refresh_token grant returns a new access token AND a new refresh token; store the new refresh token, the old one is revoked.

Marketplace Install

When a merchant installs your app from the Cartly marketplace, Cartly sends them to the Install URL 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. An app without an Install URL is installed, and the merchant connects it from your own site.

The request carries shop (the storefront host, e.g. my-shop.mycartly.pro), shop_id, install_id, timestamp (Unix seconds) and 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.

Then send the merchant to /oauth/authorize with your own state and PKCE code_challenge. You can also forward install_id: the consent page then offers only the shop the app was installed on, and Cartly refuses the authorization if the ID is not your app's install on that shop.

Verify the install request

javascript
const crypto = require('crypto');

// query = the install request's URLSearchParams
function verifyInstall(query, clientSecret, toleranceSeconds = 300) {
  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'))) < toleranceSeconds;
  return fresh && hmac.length === expected.length && crypto.timingSafeEqual(Buffer.from(hmac), Buffer.from(expected));
}

OAuth Scopes

Available permission scopes for OAuth applications

NameTypeRequiredDescription
products:readscopeNoView products and variants
products:writescopeNoCreate, update, and delete products
orders:readscopeNoView orders and order history
orders:writescopeNoUpdate order status and fulfillment
orders:ownscopeNoView only orders created by this app
customers:readscopeNoView customer information
customers:writescopeNoCreate and update customers
discounts:readscopeNoView discount codes and rules
discounts:writescopeNoCreate, update, and delete discounts
metafields:readscopeNoView custom metafields
metafields:writescopeNoCreate, update, and delete metafields
webhooks:managescopeNoManage webhook subscriptions
shop:readscopeNoView shop settings and configuration
collections:readscopeNoView product collections
collections:writescopeNoCreate, update, and delete collections
shipping:readscopeNoView shipping zones and rates
shipping:writescopeNoManage shipping configuration
analytics:readscopeNoView analytics and reports
inventory:readscopeNoView inventory levels
inventory:writescopeNoSet inventory levels (PUT /apps/api/inventory/:variant_id)
theme_extensions:writescopeNoAdd app blocks that render on the storefront (OAuth apps only)
checkout_extensions:writescopeNoAdd extensions that render during checkout (OAuth apps only)

Code Examples

bash
# Step 1: send the merchant's browser to (one line):
# https://cartly.pro/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=https%3A%2F%2Fyourapp.com%2Fcallback&scope=products%3Aread%20orders%3Aread&state=RANDOM_STATE&code_challenge=BASE64URL_SHA256_OF_CODE_VERIFIER&code_challenge_method=S256

# Step 2: Exchange code for token (send the code_verifier)
curl -X POST https://cartly.pro/oauth/token \
  -H "Content-Type: application/json" \
  -d '{"grant_type":"authorization_code","code":"AUTH_CODE","client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_SECRET","redirect_uri":"https://yourapp.com/callback","code_verifier":"CODE_VERIFIER"}'