Authentication
Request an access token
- Create a new application with your API key (Client ID) and API secret (Client Secret). For further information, refer to How to use Trustpilot APIs.
- Choose a supported Grant Type. A grant type refers to the way that the API gets your access token.
- Follow the instructions for your chosen grant type below.
Request an access token
To request a token, use your API Key, API Secret, Trustpilot username and password.
Method: POST
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
Headers
Authorization: Basic [BASE64_ENCODED(API_KEY:API_SECRET)] Content-Type: application/x-www-form-urlencoded
You must concatenate and base64 encode your API Key and API Secret.
Payload
Name | Type | Description |
---|---|---|
grant_type | Required string | Value must be set to password |
username | Required string | Your Trustpilot b2b login email |
password | Required string | Your Trustpilot b2b login password |
Example
grant_type=password&username=email@domain.com&password=Password
Response
The response contains the access token, refresh token and time of expiration:
{ access_token: "AccessToken", refresh_token: "RefreshToken", expires_in: "359999" }
When the access token expires, issue the same request to get a new token. You can also use the refresh token from the response.
1. Get an authorization code
During the log in process, the Authorization Code grant type redirects your user to a Trustpilot owned website where they are authenticated and return with a parameter containing an authorization code. You must use the returned authorization code to request an access token (step 2).
Method: GET
https://authenticate.trustpilot.com
Parameters
Name | Type | Description |
---|---|---|
client_id | Required string | The API key |
redirect_uri | Required string | The client's site URL. The URL in your app where you want to be redirected after authorization. When you get the API key from your account manager, you need to specify the redirect_uri. The redirect_uri must be https. |
response_type | Required string | Value must be set to code |
Example
Redirects back to: https://www.clientsSite.com/?code=Code
2. Request an access token
Use the authorization code that you got in the previous step to request an access token.
Method: POST
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
Headers
Authorization: Basic [BASE64_ENCODED(API_KEY:API_SECRET)] Content-Type: application/x-www-form-urlencoded
You can pass your API Key and Secret in either the Authorization header, using HTTP Basic authentication, or in the payload, using the client_id and client_secret parameters. It is recommended to use the HTTP Basic authentication approach.
Payload
Name | Type | Description |
---|---|---|
grant_type | Required string | Value must be set to authorization_code |
code | Required string | The provided code after the redirection |
redirect_uri | Required string | The client's site URL. The URL in your app where it was redirected to after authorization. It has to be identical to the redirect_uri parameter provided in the first step of authorization. The redirect_uri must be https. |
client_id | Optional string | The API key |
client_secret | Optional string | The API secret |
Example
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
grant_type=authorization_code&code=Code&redirect_uri=https://www.clientsSite.com
Response
The response contains the access token, refresh token and time of expiration:
{ access_token: "AccessToken", refresh_token: "RefreshToken", expires_in: "359999" }
When your access token expires, your user needs to log in to get a new authorization code.
Request an access token
During the log in process, the Implicit grant type redirects your user to a Trustpilot owned website where they are authenticated and return with a parameter containing an access token and expiration time.
Method: GET
https://authenticate.trustpilot.com
Parameters
Name | Type | Description |
---|---|---|
client_id | Required string | The API key |
redirect_uri | Required string | The client's site URL. The URL in your app where you want your user to be redirected to after authorization. The redirect_uri must be https. |
response_type | Required string | Value must be set to token |
Example
Redirects back to
https://www.clientsSite.com/#access_token=AccessToken&token_type=bearer&expires_in=359999
The access_token parameter is stored behind the fragment and is available to client side scripting.
- Go to the user's Trustpilot Business profile page.
- Copy the User ID.
- Provide the User ID as a header or in the request body.
Request an access token
To get an access token you need your API Key, API Secret.
Method: POST
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
Headers
Authorization: Basic [BASE64_ENCODED(API_KEY:API_SECRET)] Content-Type: application/x-www-form-urlencoded
You must concatenate and base64 encode your API Key and API Secret.
Payload
Name | Type | Description |
---|---|---|
grant_type | Required string | Value must be set to client_credentials |
Example
grant_type=client_credentials
Response
{ access_token: "AccessToken", expires_in: "359999" }When the access token expires, issue the same request to get a new token.
Method: POST
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/refresh
or
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken
Headers
Authorization: Basic [BASE64_ENCODED(API_KEY:API_SECRET)] Content-Type: application/x-www-form-urlencoded
You can pass your API Key and Secret in either the Authorization header, using HTTP Basic authentication, or in the payload, using the client_id and client_secret parameters. It is recommended to use the HTTP Basic authentication approach.
Payload
Name | Type | Description |
---|---|---|
grant_type | Required string | Value must be set to refresh_token |
refresh_token | Required string | The refresh token |
client_id | Optional string | The API key |
client_secret | Optional string | The API secret |
Example
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/refresh
grant_type=refresh_token&refresh_token=RefreshToken
Response
{ access_token: "AccessToken", refresh_token: "RefreshToken" }
Method: POST
https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/revoke
Headers
Content-Type: application/x-www-form-urlencoded
Payload
Name | Type | Description |
---|---|---|
token | Required string | The refresh token |
Example
token=7Xu4MQ9xsvUA0Tard2bIofnLjacrw7RL
Response
You receive a 200 response if the revocation succeeds.
https://api.trustpilot.com/v1/private/business-units/[YOUR BUSINESS UNIT ID]/reviews?token=[YOUR ACCESS TOKEN]Note: The returned JSON refers to the property as access_token, but when you pass it into the next API you need to call it token. To pass an access token as a header, use the following example header:
Authorization: Bearer YourAccessToken