Numberly
Introduction

Authentication

The NMP API utilizes the OAuth 2.0 standard with the client_credentials grant type (RFC 6749). This method is specifically designed for secure server-to-server communications, where your application authenticates itself rather than acting on behalf of an end user. The process consists of two main steps: obtaining a temporary access token, and subsequently using this token to authenticate your requests.

Obtaining the Access Token

To begin, you must exchange your client credentials (client_id and client_secret), provided by Numberly, for an access_token.

Technical Definition

  • HTTP Method: POST
  • Endpoint: {subdomain}.api.numberly.com/v1/oauth2/token
  • Content-Type: application/x-www-form-urlencoded

Request Body Parameters

ParameterRequiredValue / Description
grant_typeYesMust be set to client_credentials.
client_idYesYour client identifier (e.g., nmp_client_foo).
client_secretYesYour client secret (e.g., tDDyv8oLVbbPnJ7...).

Request Example

curl -X POST "https://{subdomain}.api.numberly.com/v1/oauth2/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=VOTRE_CLIENT_ID" \
  -d "client_secret=VOTRE_CLIENT_SECRET"

Response (Success)

The API returns a JSON object containing the token and its validity duration (default 1 hour / 3600 seconds).

{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}

Using the Token

Once the token is obtained, you must include it in the HTTP Authorization header of all your subsequent API requests. The token type is Bearer.

Header Format:Authorization: Bearer <your_access_token>

Authenticated Call Example

curl -X GET "https://{subdomain}.api.numberly.com/v1/campaigns" \
  -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json"

If the token is invalid or expired, the API will return an HTTP 401 Unauthorized error.

Authentication Error Management

When requesting a token, you may encounter specific errors (HTTP 400 or 401). The response body will contain a standardized error code.

Error Code (error)MeaningCorrective Action
invalid_clientClient authentication failed (wrong ID or secret).Check your credentials.
invalid_requestMissing or malformed parameter.Verify that grant_type is present.
unsupported_grant_typeUnsupported grant type.Ensure you are sending client_credentials.

Error Response Example:

{
    "error": "invalid_client",
    "error_description": "Could not authenticate the client: unknown client_id"
}

Token Revocation

If necessary (for example, in case of compromise), you can invalidate an active token via the revocation endpoint.

  • Endpoint: POST {subdomain}.api.numberly.com/v1/oauth2/revoke
  • Parameters: client_id, client_secret, and token (the token to revoke).