Quick start
Go from an API key to your first successful GET /app in a few minutes.
By the end of this page you will have made your first successful GET /app call. It walks you through the shortest working path on Production: identify one merchant from your backend, then read the app with the token you get back. The final section is one complete program that does all of it.
Prerequisites: an app in Nortly that you can create an API key for, and Node.js 20 or later (it has fetch built in). The snippets are TypeScript; drop the type annotations to use plain JavaScript. They use one base URL for the Production host:
const BASE_URL = "https://id.nortly.app/api/2026-07";1. Get an API key
Create an API key for your app in Nortly. It is bound to one app and allows POST /identify. The key is shown only once, so copy it right away and keep it in an environment variable on your backend.
export NORTLY_API_KEY="<your API key>"We recommend never putting this key in frontend code, a mobile app or a public repository.
2. Identify a merchant (backend)
Call POST /identify on the Nortly API host. Only shopId is required.
const res = await fetch(`${BASE_URL}/identify`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NORTLY_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ shopId: "1234567890", name: "Acme Test Store" }),
});
const { token, expiresAt } = await res.json();The response is 200 with the customer token:
{ "token": "EXAMPLE-NOT-A-REAL-TOKEN", "expiresAt": "2026-07-16T09:30:00.000Z" }If you only want to see that your key and host work, this one curl check is the fastest way:
curl -i -X POST "https://id.nortly.app/api/2026-07/identify" \
-H "Authorization: Bearer $NORTLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "shopId": "1234567890" }'You should see HTTP/2 200 and the x-identify-api-version: 2026-07 header. 401 unauthorized means the key is missing, malformed, unknown or revoked, or the Authorization header is not Bearer <key>: check the key and the host.
3. Hand the token to the browser
Your backend passes token to your frontend, for example in the data you already embed in the page or from your own session endpoint. The token is safe for the browser: it only gives read access to this one merchant's data for your app, and it expires after 24 hours (expiresAt).
4. Make the first GET /app
From the browser (or from Node, for a quick test), send the token as a bearer credential:
const res = await fetch(`${BASE_URL}/app`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`Identify API error ${res.status}`);
const app = await res.json();
console.log(app.id, app.isDev, app.environments);Expected body:
{
"id": 4821,
"isDev": false,
"environments": [{ "name": "API_BASE_URL", "type": "string", "value": "https://api.partner-app.test" }]
}5. Read the merchant's data
GET /customer takes the same token:
const res = await fetch(`${BASE_URL}/customer`, {
headers: { Authorization: `Bearer ${token}` },
});
const customer = await res.json(); // { nortlyId, domain, tags, customFields, review }{
"nortlyId": "cus_7f3a91",
"domain": "acme-test.myshopify.com",
"tags": [],
"customFields": [],
"review": null
}Your data is merged asynchronously after step 2. If a brand-new merchant answers 404 with {"error":"not_found"}, wait a moment and retry. We recommend retrying with a growing delay (0.5 s, 1 s, 2 s).
Next steps
- Understand the whole picture: Getting started.
- Refresh the token before
expiresAtby callingPOST /identifyagain. See Authentication. - Send more merchant data and contacts: Push merchant data.
- Read more from the browser: Read data in the browser.
- Handle failures: Errors.
Example
A complete script for Node.js 20 or later. It identifies one merchant, then reads GET /app and GET /customer with the returned token. In a real integration the first call runs on your backend and the other two in the browser; here they run in one process so you can try the whole path. Save it as quickstart.ts and run it with NORTLY_API_KEY=<your API key> npx tsx quickstart.ts.
const BASE_URL = "https://id.nortly.app/api/2026-07";
const API_KEY = process.env.NORTLY_API_KEY;
const SHOP_ID = process.env.NORTLY_SHOP_ID ?? "1234567890";
type IdentifyResponse = { token: string; expiresAt: string };
type Environment = { name: string; type: string; value: unknown };
type App = { id: number; isDev: boolean; environments: Environment[] };
type Customer = {
nortlyId: string;
domain: string | null;
tags: string[];
customFields: { name: string; type: string; value: unknown }[];
review: { rating: number; text: string; createdAt: string; updatedAt: string } | null;
};
class ApiError extends Error {
status: number;
code?: string;
constructor(status: number, code?: string) {
super(`Identify API answered ${status}${code ? ` ${code}` : ""}`);
this.status = status;
this.code = code;
}
}
async function request<T>(path: string, init: RequestInit): Promise<T> {
const res = await fetch(`${BASE_URL}${path}`, init);
if (!res.ok) {
const body = (await res.json().catch(() => ({}))) as { error?: string };
throw new ApiError(res.status, body.error);
}
return (await res.json()) as T;
}
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
// Retries the given statuses with exponential backoff: 0.5 s, 1 s, 2 s, ...
async function withRetry<T>(fn: () => Promise<T>, retryOn: number[], attempts = 5): Promise<T> {
for (let attempt = 1; ; attempt++) {
try {
return await fn();
} catch (err) {
const retryable = err instanceof ApiError && retryOn.includes(err.status);
if (!retryable || attempt >= attempts) throw err;
await sleep(500 * 2 ** (attempt - 1));
}
}
}
async function main(): Promise<void> {
if (!API_KEY) throw new Error("Set NORTLY_API_KEY to your API key.");
// 1. Backend: identify the merchant and receive a customer token.
const { token, expiresAt } = await withRetry(
() =>
request<IdentifyResponse>("/identify", {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ shopId: SHOP_ID, name: "Acme Test Store" }),
}),
[429, 503],
);
console.log(`Token issued, valid until ${expiresAt}`);
// 2. Browser side: only the customer token is needed from here on.
const headers = { Authorization: `Bearer ${token}` };
const app = await withRetry(() => request<App>("/app", { headers }), [429, 503]);
console.log("App:", app.id, app.isDev ? "development" : "production", app.environments.length, "values");
// 3. A merchant that was identified for the first time can answer 404 for a moment.
const customer = await withRetry(() => request<Customer>("/customer", { headers }), [404, 429, 503]);
console.log("Customer:", customer.nortlyId, customer.domain, customer.tags);
}
main().catch((err) => {
if (err instanceof ApiError && err.status === 401) {
console.error("401 unauthorized: check that the API key is valid and not revoked, and that you call the Nortly API host.");
} else {
console.error(err instanceof Error ? err.message : err);
}
process.exitCode = 1;
});Updated 13 days ago