Authentication & API Conventions
API keys, OAuth 2.1 developer app tokens, customer portal sessions, rate limits, idempotency, pagination, and error responses.
devhelp shop supports four distinct caller credentials depending on what you are building:
| Caller | Credential | Header | Rate limit / Scope |
|---|---|---|---|
| Headless Storefront | Publishable key (dh_pk_live_…) | x-api-key: dh_pk_live_… | 600 req/min · /storefront/v1/* · enforces allowed browser Origin |
| Private Store App | Secret key (dh_sk_live_…) | x-api-key: dh_sk_live_… | 300 req/min · /admin/v1/* for one store · server-side only |
| Public Developer App | OAuth 2.1 Bearer JWT (dh_app_… client) | Authorization: Bearer <jwt> | /admin/v1/* · scoped to EXTERNAL_APP_SCOPES (token ∩ consent ∩ install) · see Public Developer Apps |
| Customer Portal Session | Publishable key + opaque token | x-api-key + x-dh-customer-token | /storefront/v1/account/* · store-scoped shopper session · see Customer Portal API |
API keys (single-store)
Create and revoke keys in Settings → API keys inside app.devhelp.pk.
Keep secret keys server-side only
Never embed a dh_sk_live_… secret key in browser code, mobile apps, or
public repositories. createAdminClient in @devhelp/shop/server throws
immediately if invoked in a browser environment.
Sensitive administrative routes (such as managing team members, API keys, billing cards, developer app submissions, or installing apps) require a signed-in merchant dashboard session and refuse both secret keys (where restricted) and developer app OAuth tokens with 403.
OAuth 2.1 for multi-store developer apps
If you are building an app for multiple merchants (distributed in the devhelp shop app catalogue or via unlisted install links), use OAuth 2.1 Authorization Code + PKCE (S256) with confidential client_secret_basic credentials (dh_app_… / dh_cs_…) and resource=https://api.devhelp.pk. Tokens are checked against live installation status, consent, and scopes on every request, and revoke immediately on uninstall, disable, or suspension. See Public Developer Apps for the complete flow.
Idempotency
Write endpoints that create financial or operational records accept an Idempotency-Key header (for example admin.orders.create, admin.fulfillments.create, admin.fulfillments.createReturn, admin.orders.refund, admin.orders.recordCashRefund, and admin.bookings.recordPayment).
When using @devhelp/shop/server, the SDK attaches a generated Idempotency-Key automatically if you do not supply one. For safe retries across network failures in your own job queue, pass a deterministic key per business operation:
await admin.orders.create(orderPayload, {
context: { idempotencyKey: `erp-import-${externalOrderId}` },
});Cursor pagination
List endpoints return cursor-paginated responses:
{
"items": [],
"nextCursor": "eyJjcmVhdGVkQXQiOi4uLn0"
}Pass cursor and limit on subsequent requests until nextCursor is null.
Error handling
Errors return standard HTTP status codes (400, 401, 403, 404, 409, 422, 429, 500) with a structured JSON body containing a machine-readable code and message.
With @devhelp/shop, catch typed errors using isShopError:
import { isShopError } from "@devhelp/shop";
try {
await admin.products.get({ id });
} catch (error) {
if (isShopError(error)) {
console.error(error.code, error.status, error.message);
}
}