Authentication
Contentsquare APIs authenticate via server-to-server OAuth 2.0 credentials generated from the Contentsquare console.
The flow consists of calling an authentication endpoint with a client_id / client_secret pair to retrieve an access token that remains valid for 1 hour. Use this JWT token as a Bearer token in the headers of your HTTPS requests, in the form Authorization: Bearer YOUR_ACCESS_TOKEN.
You can generate a client_id / client_secret pair from the Contentsquare console ↗, as a Contentsquare administrator. See How to create API credentials ↗.
Create OAuth credentials at the project level, to access resources of a specific project only.
Authentication endpoint
Section titled Authentication endpointPOST https://api.contentsquare.com/v1/oauth/token ↗
Request parameters
client_idstring RequiredThe OAuth
client_idgenerated from the Contentsquare console.client_secretstring RequiredThe OAuth
client_secretgenerated from the Contentsquare console.grant_typestring RequiredAlways set it to
"client_credentials", as required by the OAuth 2.0 standard.scopestring RequiredUse
"surveys".project_idintegerSpecify which project of the account you want to target.
Request example
curl --location 'https://api.contentsquare.com/v1/oauth/token' \--header 'Content-Type: application/json' \--data '{ "client_id": "c3133d76-a768-4f5a-XXX", "client_secret": "0ISL0DEC;UyYKB;riWRS0EXXX", "grant_type": "client_credentials", "scope": "surveys"}'Response example
{ "access_token": "eyJhbGciOiJSIsImtpY5MTXXX.CNTcKWAUb2mTp2cZyiDRYYOtGCKXXX", "token_type": "bearer", "expires_in": 3600, "scope": "surveys"}Using the access token
Section titled Using the access tokencurl --location 'https://api.contentsquare.com/v1/public/projects/42/surveys' \--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'Refresh your access token
Section titled Refresh your access tokenThe access token is valid for 1 hour. If you query the API with an expired or invalid token, you receive a 401 Unauthorized error.
In case of an invalid token:
{ "success": false, "errorMessage": "Auth token is invalid.", "errorCode": "JWT_INVALID"}In case of an expired token:
{ "success": false, "errorMessage": "Auth token is expired.", "errorCode": "JWT_EXPIRED"}In that case, use your OAuth credentials (your client_id / client_secret pair) to request a new access token.
Example of authentication flow
Section titled Example of authentication flowThe following JavaScript code retrieves an access token and then uses it to list the surveys of a project:
const authResponse = await fetch("https://api.contentsquare.com/v1/oauth/token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ client_id: "<your_client_id>", client_secret: "<your_client_secret>", grant_type: "client_credentials", scope: "surveys", }),});const { access_token } = await authResponse.json();
const surveysResponse = await fetch("https://api.contentsquare.com/v1/public/projects/42/surveys", { headers: { Authorization: `Bearer ${access_token}` },});const { results, next_cursor } = await surveysResponse.json();
