ClocknextClocknextHelp
DocumentationAPI ReferenceMCP Tools
Dashboard

Get started

OverviewQuickstart

Good to know

Response formatHandling errorsPaginating resultsSending data reliablyYour own customer idsWebhooks

API reference

Signals

Record credit POSTRecord outcome POSTComplete outcome POSTRecord wallet POSTRecord unit POSTComplete composite POSTList raw signals GETRetry signals POSTList Customer Usage Log GETLook Up Usage Logs by ID GET

Deprecated

Record credit POSTRecord outcome POSTComplete outcome POSTRecord wallet POSTRecord unit POSTComplete composite POSTList raw signals GETRetry signals POST

Customers

List customers GETCreate a customer POSTGet a customer GETUpdate a customer PATCHDelete a customer DELETEGet a customer's balances GETGet a customer's wallet ledger GETSet a customer's low-balance alert for wallet PUTGet a customer's current plan GETChange a recurring grant PUTUpdate a customer's card POSTGet a customer's invoice balance GETAdjust a customer's invoice balance POST

Deprecated

List Customer Usage Log GETLook Up Usage Logs by ID GET

Manage

Manage a customer's credit balance POSTManage a customer's outcome balance POSTManage a customer's unit balance POSTManage a customer's composite balance POSTManage a customer's wallet balance POST

Members

List a customer's members GETAdd a member POSTUpdate a member PATCHRemove a member DELETE

Plans and Entitlements

PlansPackagesCreditsOutcomesUnitsComposites

Taxes

List taxes GETCreate a tax POSTGet a tax GETUpdate a tax PATCH

Purchases

List purchases GETCreate a purchase POSTGet a purchase GETUpdate a purchase's auto-payment setting PATCHCancel a purchase POST

Checkout

Create a checkout POST

Subscriptions

List subscriptions GETGet a subscription GETCancel a subscription POSTAdd packages to a subscription POSTRemove a package from a subscription POST

Plan changes

List plan changes GETPreview a plan change POSTChange a customer's plan POSTGet a plan change GET

Invoices

List invoices GETGet an invoice GETMint a hosted pay link GETRecord a payment POST

Credit notes

List credit notes GETCreate a credit note POSTGet a credit note GETVoid a credit note POST

Refunds

List refunds GETRefund to the card POSTGet a refund GET

Payments

List payments GETGet a payment GET

Webhooks

Customer Portal

Mint a customer-portal access token POST

API Reference

Handling errors

Every status code the API returns, what it means, and how to handle it.

When a request fails, the HTTP status and statusCode agree, statusDetail.status is ERROR, result is an empty object, and the reason is in statusDetail.message. Some refusals also name it in statusDetail.code (see Refusal codes):

{
  "statusCode": 400,
  "statusDetail": { "status": "ERROR", "message": "email must be a valid email" },
  "result": {}
}

Status codes

StatusMeaningWhat to do
400 Bad RequestThe request was malformed — invalid JSON, a bad query parameter, a field that failed validation (wrong type, out-of-range, or missing required), or a rejected business rule (e.g. an inactive plan, a past billing date).Read statusDetail.message for the offending field or rule and fix the request.
401 UnauthorizedThe API key is missing or unknown.Send a valid Authorization: Bearer cnk_… header. See Settings → API Keys.
403 ForbiddenYour Clocknext plan does not include the feature (statusDetail.code FEATURE_LOCKED); on every route, the workspace is locked because its Clocknext subscription was cancelled (WORKSPACE_LOCKED); or an explicit organizationId on /portal/token doesn't match the key's organisation.See Feature locks. For a mismatch, send the correct organizationId, or omit it.
404 Not FoundThe record doesn't exist — or belongs to another organisation (the two are masked as one).Check the id. A foreign id looks identical to a missing one by design.
409 ConflictThe request clashes with current state — e.g. a duplicate member email, archiving a customer whose plan is still active, a subscription already cancelled, or paying an invoice that isn't OPEN.Reconcile with the current state, then retry.
422 Unprocessable EntityThe body is well-formed but can't be applied to the current state — raised by the balance adjustments when the entitlement isn't on the customer's plan, or a Reserved Wallet reduce would go below 0. It is also the answer to an idempotency key reused for a different credit note, refund, plan change or invoice-balance adjustment (IDEMPOTENCY_KEY_REUSED). (Field-level validation is 400, not 422.) A signal is never refused this way: it gets a 202 and, when it can't be counted, waits as PENDING (see List raw signals).Read statusDetail.message; fix the referenced entity. Not retryable unchanged.
429 Too Many RequestsYour organisation sent more signals in one second than its limit (200 a second by default), or too many signal retries are running for it.Wait the seconds in the Retry-After header (1 second when it is not there), then retry with the same idempotency key.
503 Service UnavailableThe signal could not be accepted right now (a short outage, or the customer of an externalId could not be looked up). Nothing is recorded.Retry with backoff and the same idempotency key.
500 Internal Server ErrorSomething went wrong on our side.Retry with backoff; if it persists, contact support.

Why foreign ids are 404, not 403

A key is scoped to one organisation, and referencing an id from another organisation returns 404 everywhere — the same as an id that doesn't exist. That's deliberate: it stops a key probing for valid foreign ids by telling "forbidden" apart from "not found". The only endpoint that distinguishes them is /portal/token.

Feature locks

Your Clocknext plan can leave out some features. When it does, every API route of that feature answers 403 until Clocknext support unlocks it. A retry does not help. The answer names the feature in three places: statusDetail.code is FEATURE_LOCKED, result.feature is the feature, and the X-Feature-Locked header repeats it.

{
  "statusCode": 403,
  "statusDetail": {
    "status": "ERROR",
    "message": "Invoices is not included in your Clocknext plan. Contact support to unlock.",
    "code": "FEATURE_LOCKED"
  },
  "result": { "error": "feature_locked", "feature": "INVOICES" }
}
FeatureRoutes that answer 403 when it is locked
PURCHASESGET /purchases, GET /purchases/{id}, GET /subscriptions, GET /subscriptions/{id}, GET /customers/{id}/plan (and its ext/{externalId} twin), and every /plan-changes route (list, preview, create, get). Creating, updating and cancelling a purchase stay open.
INVOICESGET /invoices, GET /invoices/{id}, GET /invoices/{id}/pay-link, every /credit-notes and /refunds route, GET /customers/{id}/invoice-balance and POST /customers/{id}/invoice-balance/adjust (and their ext/{externalId} twins). Recording a payment (POST /invoices/{id}/pay) stays open.
PAYMENTSGET /payments, GET /payments/{id}
TAXESGET/POST /taxes, GET/PATCH /taxes/{id}
COMPOSITESGET/POST /composites, GET/PATCH /composites/{id}, POST /composites/{id}/archive and /unarchive, POST /customers/{id}/composites/adjust (and its ext/{externalId} twin)
CUSTOMER_PORTALPOST /portal/token
INTEGRATIONSNo API route. Locks the integration settings in the dashboard.
CREDIT_RULESNo API route, and no error. Credit rules stop applying to new signals; signals are still counted.

A lock never stops signals, and never touches data you already have: invoices, renewals and auto-pay keep running.

Locked workspace

When a workspace's Clocknext subscription is cancelled, every route answers 403 with statusDetail.code WORKSPACE_LOCKED and the header X-Workspace-Locked: 1, until Clocknext support restores access. If a route is also feature-locked, you get the feature lock.

Refusal codes

A refusal of a credit note, refund, plan change, invoice-balance adjustment or subscription cancel, or a package added to or removed from a subscription, names its reason in statusDetail.code. Branch on the code, not on the message. When an amount was too large, result holds the most that could go now, in USD: maxSubtotalUsd for a credit note (before tax) and maxAmountUsd for a refund.

{
  "statusCode": 400,
  "statusDetail": {
    "status": "ERROR",
    "message": "The most that can be refunded to the card now is $100.00.",
    "code": "AMOUNT_EXCEEDS_REFUNDABLE_TO_CARD"
  },
  "result": { "maxAmountUsd": 100 }
}
CodeStatusMeaning
INVALID_REQUEST400The body or query failed validation: a missing or wrong field, an unknown parameter, a plan change that sends timing, effectiveDate or billing, or a startNewCycle that is not true or false.
INVOICE_NOT_OPEN_OR_PAID400Only an OPEN or a PAID invoice can be credited.
DESTINATION_REQUIRED_FOR_PAID_INVOICE400A credit note on a PAID invoice needs a destination: CREDIT_TO_INVOICE_BALANCE or REFUND_TO_CARD.
DESTINATION_DOES_NOT_MATCH_INVOICE_STATUS400An OPEN invoice takes only REDUCE_OPEN_INVOICE, and a PAID one can't take it.
CARD_REFUND_NOT_POSSIBLE400The money can't go back to a card, for instance because the invoice wasn't paid by card at a payment gateway. Send it to the invoice balance instead. A cancel that refunds the unused time to the card gets it when the card paid less than the whole refund.
AMOUNT_EXCEEDS_CREDITABLE_AMOUNT400The amount is more than can still be credited. maxSubtotalUsd is the most, before tax.
AMOUNT_EXCEEDS_REFUNDABLE_TO_CARD400The amount is more than can go to the card. maxSubtotalUsd (credit note) or maxAmountUsd (refund) is the most.
AMOUNT_EXCEEDS_INVOICE_BALANCE400The amount is more than the customer's invoice balance. A refund also carries maxAmountUsd.
INVOICE_NOT_OPEN, CREDIT_NOTE_ALREADY_VOID400A credit note can be voided only while its invoice is OPEN, and only once.
CUSTOMER_HAS_NO_ACTIVE_PLAN, CURRENT_PLAN_NOT_ON_SUBSCRIPTION_FLOW400The plan change can't be made: the customer has no running plan, or their plan isn't on the subscription flow.
NEW_PLAN_INACTIVE, NEW_PLAN_HAS_NO_PRICING, ALREADY_ON_THIS_PLAN, LAST_DAY_OF_PERIOD400The new plan is inactive or has no pricing, the customer is already on it, or today is the last day of the period.
REFUND_REQUIRES_IMMEDIATE_CANCELLATION, REFUND_DESTINATION_REQUIRED, REFUND_DESTINATION_WITHOUT_REFUND400A cancel asked for a refund with atPeriodEnd: true, asked for a refund without refundTo, or sent refundTo without proration REFUND_UNUSED_TIME.
REFUND_AMOUNT_NOT_POSSIBLE400, 409The credit note for the unused time couldn't be made, for instance because a payment for the invoice is running. The subscription is not cancelled. The message says why.
INVOICE_NOT_FOUND, CREDIT_NOTE_NOT_FOUND, REFUND_NOT_FOUND, CUSTOMER_NOT_FOUND, PLAN_NOT_FOUND, PLAN_CHANGE_NOT_FOUND, SUBSCRIPTION_NOT_FOUND, PACKAGE_NOT_FOUND404The record doesn't exist, or belongs to another workspace. On a package remove, PACKAGE_NOT_FOUND means no such package on this subscription; on the package catalog, no such package in the workspace.
AUTO_CHARGE_IN_PROGRESS, CUSTOMER_PAYMENT_IN_PROGRESS, PAYMENT_LINK_COULD_NOT_BE_CLOSED409A payment for the invoice is running, or its pay link couldn't be closed. Retry in a few minutes.
CURRENT_PLAN_ALREADY_ENDING, PLAN_CHANGE_ALREADY_IN_PROGRESS, RENEWAL_UNPAID_ON_HOLD, SUBSCRIPTION_NOT_RUNNING, UNUSED_TIME_CREDIT_FAILED409The plan is already ending, another change is running, the renewal is unpaid, the subscription isn't running, or the unused time couldn't be credited.
NOTHING_TO_REFUND409A cancel asked to refund the unused time, but there is nothing to refund: the subscription hasn't started and nothing was paid for it, its renewal is unpaid, nothing was paid for the period, no unused days are left, or it was all credited already (also by a plan change). The subscription is not cancelled.
SUBSCRIPTION_ALREADY_CANCELLED, SUBSCRIPTION_ALREADY_MARKED_FOR_CANCELLATION409The subscription is already cancelled, or already marked for cancellation.
PLAN_CHANGE_IN_PROGRESS409A plan change of the subscription is being made, so it can't be cancelled yet: not now, not at the end of the period, with or without a refund. Nothing is changed. Ask again in a few minutes. A second plan change gets PLAN_CHANGE_ALREADY_IN_PROGRESS instead.
CANCEL_FAILED400, 500The subscription couldn't be cancelled. When a refund was made first, the message says so: ask again, and nothing is refunded twice.
REFUND_DESTINATION_MISMATCH409A cancel asked again after a failure, with another refundTo than the refund already made. Ask again with the same refundTo: nothing is refunded twice. Nothing is changed.
CANCEL_REFUND_VOIDED409A cancel asked again after a failure, but the credit note of the refund it made was voided, so nothing was refunded. Nothing is cancelled. Contact support.
SUBSCRIPTION_NOT_ACTIVE409A package can't be added: the subscription is on hold, marked for cancellation, cancelled, or on a free plan.
PACKAGE_ARCHIVED409The package is archived. Unarchive it before you add it.
PACKAGE_ENTITLEMENT_NOT_ON_PLAN, PACKAGE_ENTITLEMENT_METERED409The subscription's plan doesn't have one of the package's entitlements as advance, or meters it. For wallet money: the plan has no wallet, or its wallet is metered.
PACKAGE_ENDED, PACKAGE_ALREADY_ENDING409The package has already ended, or is already marked for removal (atPeriodEnd: true again).
PACKAGE_AWAITING_PAYMENT409The package's invoice isn't paid yet, so it can't be removed. Void its invoice instead.
PACKAGE_NAME_TAKEN409Packages: another package of the workspace has this name.
RENEWAL_PAID_IN_PART, CHARGE_IN_FLIGHT409On hold, the package's line can't come off the renewal: part of it is paid (refund or void it first), or a card charge on it is settling (retry in a few minutes).
USAGE_UNAVAILABLE409What the package used can't be read right now, so it can't end now. Retry in a minute.
IDEMPOTENCY_KEY_REUSED422The idempotencyKey was already used for a different request (for a package attach: other packages or another subscription). See Sending data reliably.
NEW_PLAN_SETUP_FAILED, INTERNAL_ERROR500The new plan could not be set up, or the call failed on our side.

The @clocknext/sdk client puts the code on error.code, and the limits on error.maxSubtotalUsd and error.maxAmountUsd. A reused key is a ConflictError.

Handling errors

Treat any non-2xx status as a failure and read statusDetail.message for the reason. When statusDetail.code is present, branch on it instead of the message. 4xx codes mean your request needs to change and won't succeed on a blind retry; 500 is transient and safe to retry.

The @clocknext/sdk client throws a typed error for each status, all extending ClockNextError (with .status, .code and .retryable), so you can branch on the failure instead of parsing the message:

import {
  AllowanceError,
  AuthError,
  FeatureLockedError,
  NotFoundError,
  WorkspaceLockedError,
} from "@clocknext/sdk";

try {
  await cnk.invoices.list();
} catch (err) {
  if (err instanceof FeatureLockedError) {
    // 403: your plan does not include err.feature ("INVOICES")
  } else if (err instanceof WorkspaceLockedError) {
    // 403: the workspace's Clocknext subscription was cancelled
  } else if (err instanceof NotFoundError) {/* 404 */}
  else if (err instanceof AuthError) {/* 401 */}
  else if (err instanceof AllowanceError) {/* 422: an adjustment the plan does not allow (never a signal) */}
}

FeatureLockedError and WorkspaceLockedError are both a ForbiddenError, and the SDK never retries them.

Retries

Only retry codes that can succeed unchanged:

  • Retry 500 (and network/timeout failures) with exponential backoff.
  • Do not retry 4xx — the request itself is the problem; fix it first.

Be careful retrying non-idempotent writes (a POST that creates a record). If a POST /customers times out you can't tell whether it landed, so a blind retry risks a duplicate. Prefer to look the record up before retrying, or use the @clocknext/sdk client, which only auto-retries replay-safe calls.

Response format

Every endpoint — success or error — returns the same predictable envelope. Here's the contract.

Paginating results

Page through list endpoints with limit and cursor.

On this page

Status codesFeature locksLocked workspaceRefusal codesHandling errorsRetries