Manage API access
Choose an authentication method, issue tokens and signature keys, and rotate them before they expire.
Your goal
Give your integrations access to the mediarithmics API with the authentication method that fits where the code runs, and keep track of every credential you have issued so none of them expires unnoticed or outlives its purpose.
Expected outcome
Server-side integrations authenticate with long-term API tokens borne by service accounts; public applications sign their calls instead of carrying a token; and an administrator can see, at any moment, every credential in the organisation, when it was last used, and when it expires.
Before you start
A service account to bear each production credential, so that deleting a person's account does not cancel a production integration. See Manage users and roles.
At least one role on the account. A user with no role has no access to anything, the API included - see Manage users and roles.
An organisation administrator or community administrator role, if you intend to manage credentials for the whole organisation rather than only your own.
Choose the method
Direct server-to-server integration
Long-term API token
Live data collection from applications - mobile, CTV, anything running on a public network
Signature authentication
The platform is built on an API-first model: essentially anything you can do in the interface or with the tools can be done through the API. The base URL is https://api.mediarithmics.com, over HTTPS only - support for HTTP has been discontinued. Make the base URL easy to change in your integration, as it may change in future.
Where credentials live
Settings > My Account > API Tokens
Create and list your own long-term API tokens.
Any user, for their own account.
Settings > Organisation > API Authentication
View every API token in the organisation, for user accounts and service accounts alike. Create, edit, and revoke service account tokens.
Community and organisation administrators.
Long-term API tokens
A long-term API token identifies a user and has a longer expiration delay than a session - usually 12 to 24 months. A user can hold several tokens, which is what makes rotation possible without downtime.
Create a token
Open Navigator.
Go to Settings.
Open My Account > API Tokens.
Click New API Token.
An administrator creating a token for a service account does it from Settings > Organisation > API Authentication instead, where service account tokens can also be edited and revoked.
Body: { "name": "<the name of the API token>" }
The response returns the token, including its value, creation_date, and expiration_date.
List the tokens of a user with:
Use the token
Pass the token in the Authorization header of every request, with Content-Type: application/json on any request carrying a body.
Govern the tokens you have issued
Settings > Organisation > API Authentication is the single dashboard for the credentials of an entire organisation. Administrators use it to:
See everything in one place - all API tokens across the organisation, for both user accounts and service accounts.
Manage service accounts without a developer - create, edit, and revoke service account tokens directly in the interface.
Monitor activity - the Last Used date of every token tells you whether an integration is still alive.
Anticipate expirations - track expiration dates so an integration never goes dark because a token silently lapsed.
Clean up - identify zombie tokens that are no longer in use and remove them.
Rotate a token
Because a user can hold several tokens at once, a rotation never needs a gap in service.
Signature authentication
Signature authentication is for environments where the calling party operates on a public network, or in a published mobile or CTV app - situations where the communication could be intercepted or the app decompiled. It is the preferred choice for app tracking.
The caller is authenticated with a message authentication code computed with HMAC-SHA256. Like an API token, a signature key is linked to a mediarithmics user, so create a technical user to bear it.
Generate a secret key
scheme
HMAC_SHA256
key_id
A unique string identifying your secret key. The API returns an error if the value is already used. You use this value when signing calls.
The response contains id, user_id, creation_ts, expiration_ts, key_id, scheme, and secret_key - a 16-byte value provided as a hexadecimal string.
Sign a call
Every signed call carries these headers:
X-Mics-Mac
The digest of the input data - the message authentication code.
X-Mics-Key-Id
The key_id of the secret key.
X-Mics-Ts
The timestamp used in the digest, in milliseconds.
The message to sign is built from these values in this order, separated by \n:
The URI of the API method used.
The
key_idyou chose when creating the secret key.A timestamp in milliseconds, generated at the time of the call.
The request body as a string.
The digest is computed with HMAC-SHA256 using the secret_key, and presented as a Base64 string. Use a digest library for your platform rather than implementing the algorithm.
Compute the digest
The signing helper is a handful of lines on every platform. For a complete integration built around one of these - payload, headers, and the call itself - see the samples on App tracking, which cover iOS, Android, Tizen and webOS, Android TV and Roku.
What API responses look like
Useful to know when you wire up error handling: every result is wrapped.
Single resource
status (ok or error), data
Resource list
status, data, count (elements in this page), first_result (offset of the first element), max_results (page size), and total on paginated APIs (items available across all pages)
Error
status (error), error (the message), mics_error_id
Browse paginated lists with the first_result and max_results query parameters:
Requests with a body must carry Content-Type: application/json.
Troubleshooting
A new user or service account cannot call anything
It has no role. Grant one - see Manage users and roles.
POST /api_tokens is refused
Creating a token by API requires an existing token. Generate the first one in Navigator.
A listed token's value is truncated
Listing tokens never returns complete values. Store a token when you create it.
The secret_key is lost
It is only readable in the creation response. Generate a new key and update the application.
A signed call is rejected on an endpoint that works with a token
Signature authentication only covers the actions listed above. Anything else needs a long-term API token.
An integration stops without warning
Its token expired. Check expiration dates in API Authentication and rotate ahead of time.
Any API error you cannot explain
Keep the mics_error_id from the failing response. It is the identifier your Account Manager needs to troubleshoot.
Verify
Each integration authenticates with the method matching where its code runs.
Production tokens are borne by service accounts, not by people.
Every token in API Authentication is accounted for: you know which integration uses it, and when it expires.
No token shows a Last Used date that stopped moving long ago.
Public applications carry a
key_id, never asecret_keythat can be extracted.
Related pages
Last updated
Was this helpful?