Skip to content

Authentication and errors

This page explains how to authenticate API requests to nps.today and how to handle the errors the API can return. Endpoints, parameters and response schemas are in the API reference, which is generated from the live services. This page only covers what the reference does not.

At a glance

Choose how to authenticate

Method Use it when Header
OAuth 2.0 (recommended) You build a server integration, or users sign in to your application Authorization: Bearer <access token>
API key The system you connect can only send a fixed header or value, for example a webhook or a no-code tool Authorization: apikey <your API key>

nps.today is an OAuth 2.0 and OpenID Connect authorization server. You get a short-lived access token from the token endpoint and send it as a Bearer token on every request to the nps.today API.

The token endpoint, all grant types, the scopes and the token lifetimes are described in the API reference: POST /account/connect/token. In short:

  • Server integrations use the client credentials flow (grant_type=client_credentials) with a client ID and client secret. Applications are registered by nps.today, so contact [email protected] to get a client ID and client secret.
  • Applications where users sign in use the user login flow: the user authenticates, then selects a tenant.

Steps for a server integration:

  1. Get a client ID and client secret from nps.today.
  2. Request an access token from POST /account/connect/token with grant_type=client_credentials. Use the Client credentials example in the API reference.
  3. Send the token in the Authorization header of every request:

    Authorization: Bearer <access token>
    
  4. When the token expires (see expires_in in the token response), request a new one. The client credentials flow does not return a refresh token.

Keep your client secret safe

Store the client secret on your server only, never in a browser or mobile app. Cache the access token and reuse it until it expires instead of requesting a new token for every call.

Authenticate with an API key

Use an API key when the system you connect cannot request a token first, for example a webhook from another system or a no-code tool.

  1. Create an API key in app.nps.today. See Create an API key.
  2. Send the key in the Authorization header of every request, with the word apikey before it:

    Authorization: apikey <your API key>
    

Code samples in the API reference

The code samples in the API reference show Authorization: Bearer YOUR_SECRET_TOKEN, which is the OAuth 2.0 access token. When you call the API with an API key, replace that header with Authorization: apikey <your API key>.

If your system cannot set the Authorization header

Some systems cannot send a custom header. Use one of these instead:

Keep your API key safe

  • Treat the API key as a password. Anyone with the key can call the API for your account.
  • Create one key per integration, so you can delete a single key without breaking other integrations. See Create an API key.

HTTP status codes and campaign member status codes

nps.today uses two kinds of status codes. Do not mix them up:

Status code What it tells you Where to find it
HTTP status code, for example 200 or 401 Whether the API accepted your request The HTTP response
Campaign member status code (AdditionStatus), for example 4001 What happened to the survey after the respondent was added: sent, throttled, bounced and so on The campaign member's history, and the additionStatus field. See Status codes.

A request can be accepted with HTTP 200 and still end with an error status on the campaign member, for example 4001 (Duplicate) or 4002 (Throttled).

Handle errors

HTTP status Meaning What to do
400 Bad Request The request failed validation. Many endpoints return a problem details body with type, title, status and detail. Read title and detail, fix the request and do not retry it unchanged.
401 Unauthorized The access token is missing or expired, or the API key is missing, wrong or deleted. Request a new access token. For an API key, check the Authorization header format and that the key still exists and is active under Account > Authentication > Api keys.
402 Payment Required Your account has used all its surveys, or all its SMS on an SMS campaign. The endpoints that add respondents return this, and the respondent is not added. Do not retry. Contact [email protected] to get more surveys or SMS.
403 Forbidden The token, key or user does not have access to the resource. Check that you are calling the right account, and that the application or user has the permission.
404 Not Found with an empty body The URL path does not exist. Check the path and its casing against the API reference.
404 Not Found with a JSON body (type, title, status, traceId) The endpoint exists, but the resource you asked for does not, for example a campaign ID that does not exist. Check the ID.
429 Too Many Requests You exceeded the rate limit. Wait and retry with exponential backoff. You are not locked out.
5xx A temporary error on our side. Retry with exponential backoff. If it continues, check the status page.

Retries

  • Retry only on 429 and 5xx, with exponential backoff and jitter, and stop after a few attempts.
  • Do not retry 400, 401, 402, 403 or 404. They will fail again until the request is fixed.
  • Log the response body of failed requests. It usually explains what is wrong.

Requests that never reach nps.today

If your client gets a connection or TLS error and no HTTP status code, the request did not reach our service, so we cannot see it in our logs. Check that your client uses TLS 1.2 or newer and that it trusts the certificate chain rather than a pinned certificate. See API certificate and TLS.

Paging

Endpoints that return lists use skip and take instead of page numbers. See Using skip and take for pagination for the pattern and an example.

Verify it worked

  1. Call an endpoint that only reads data, for example GET /campaigns:

    curl --location 'https://api.nps.today/campaigns' \
    --header 'Authorization: Bearer <access token>'
    
    curl --location 'https://api.nps.today/campaigns' \
    --header 'Authorization: apikey <your API key>'
    
  2. A 200 response with a list of your campaigns means the authentication works.

  3. A 401 response means the token has expired or the header or key is wrong. Check the format Bearer <access token> or apikey <your API key>.