Authentication

Authenticate every call with an API key of your workspace and understand 401, 403 and workspace scoping.

After this page you will be able to authenticate your calls, tell a 401 from a 403 and keep your key safe.

Prerequisites: an API key of your workspace with the reviews:read permission (ask your Nortly workspace admin), and Node.js 20 or later for the example at the end.

The API key

Every versioned route (everything under /api/<version>/) needs an API key. A key belongs to exactly one workspace and carries a set of permissions. You send it in the Authorization header as a bearer token:

const headers = { Authorization: `Bearer ${process.env.NORTLY_API_KEY}` };

The only route without authentication is the operational check GET /, which answers workspace-api ok and is meant for uptime monitors.

Permissions

A route needs one permission. Today every reviews route needs reviews:read:

RoutePermission
GET /api/2026-07/reviewsreviews:read
GET /api/2026-07/reviews/countreviews:read
GET /api/2026-07/reviews/{id}reviews:read

New resources will come with their own permissions. Ask your workspace admin for a key with exactly the permissions your integration needs.

Workspace scoping

Whatever you call, you only see the data of the workspace your key belongs to. There is no parameter to select another workspace. A review of another workspace behaves exactly like an id that does not exist: the answer is 404 with code NOT_FOUND.

401 and 403

StatuscodeMeaningWhat to do
401UNAUTHORIZEDThe key is missing, malformed, invalid or revoked.Check the Authorization: Bearer <api key> header and the key itself; ask your admin for a new key if needed.
403FORBIDDENThe key is valid but does not carry the permission the route needs.Ask your admin for a key with reviews:read.

A 401 may arrive without the JSON envelope, so decide on the HTTP status code and do not require a JSON body for it. Neither status is worth retrying unchanged.

if (response.status === 401) throw new Error("API key missing or invalid");
if (response.status === 403) throw new Error("API key lacks the reviews:read permission");

Keeping the key safe

We recommend:

  • Keep the API key on your server only, for example in an environment variable or your secret store. Never put it in a browser, a mobile app or a public repository.
  • Do not log the Authorization header.
  • Use a separate key per integration so you can revoke one without affecting the others.
  • If a key may have leaked, ask your workspace admin to revoke it and issue a new one.

The API does not answer cross-origin browser preflight requests; call it from your backend and expose only what your front end needs.

Next steps

  • Reviews: what you can read with a reviews:read key.
  • Errors: every error code and what to do.
  • Overview: how a call looks end to end.

Example

A complete program that calls a protected route and reacts to each authentication outcome. It reads the key from NORTLY_API_KEY. Run it with NORTLY_API_KEY=<your key> npx tsx auth-check.ts.

const BASE_URL = "https://api.nortly.app";
const API_KEY = process.env.NORTLY_API_KEY;

if (!API_KEY) {
  throw new Error("Set NORTLY_API_KEY to an API key with the reviews:read permission");
}

type CountResponse = { success: true; data: { count: number } };
type ErrorResponse = { success: false; message: string; code: string };

async function checkKey(): Promise<void> {
  const response = await fetch(`${BASE_URL}/api/2026-07/reviews/count`, {
    headers: { Authorization: `Bearer ${API_KEY}` },
  });

  if (response.status === 401) {
    // The body may be missing: use the status code only.
    console.error("The API key is missing or invalid. Ask your workspace admin for a new key.");
    process.exitCode = 1;
    return;
  }

  if (response.status === 403) {
    const error = (await response.json()) as ErrorResponse;
    console.error(`The key is valid but lacks the permission: ${error.code} - ${error.message}`);
    process.exitCode = 1;
    return;
  }

  if (!response.ok) {
    const error = (await response.json()) as ErrorResponse;
    console.error(`Unexpected answer ${response.status}: ${error.code}`);
    process.exitCode = 1;
    return;
  }

  const body = (await response.json()) as CountResponse;
  console.log(`The key works. Your workspace has ${body.data.count} published review(s).`);
}

await checkKey();

Expected output with a valid key:

The key works. Your workspace has 128 published review(s).

Did this page help you?