node-trustpilot
node-trustpilot copied to clipboard
OAuth2 authentication with client_credentials grant fails with HTTP 520
I'm trying to obtain an access token using the documented OAuth2 client_credentials grant:
import { TrustpilotApi } from "trustpilot";
;(async () => {
const client = await new TrustpilotApi({
key: '<api_key>',
secret: '<api_secret>',
grantType: 'client_credentials',
baseUrl: 'https://api.trustpilot.com'
}).authenticate();
const res = await client.get('/v1/business-units/all');
console.log(res.data);
})()
However, authentication fails with:
status: 520,
statusText: 'Unknown error',
headers: Object [AxiosHeaders] {
'content-type': 'text/plain',
'content-length': '0',
connection: 'close',
date: 'Tue, 20 Aug 2024 13:02:05 GMT',
'x-cache': 'Error from cloudfront',
via: '1.1 9aac88bd0767f985559187c36e716276.cloudfront.net (CloudFront)',
'x-amz-cf-pop': 'CHP50-C2',
'x-amz-cf-id': 'iX0LXSapKKvz7glJYMw9LrevY8t4kOTugsUdn1GtQavCzpVGSeE0IQ=='
},
config: {
transitional: [Object],
adapter: [Array],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object [AxiosHeaders]],
auth: [Object],
baseURL: 'https://api.trustpilot.com',
method: 'post',
url: '/v1/oauth/oauth-business-users-for-applications/accesstoken',
data: 'grant_type=client_credentials'
},
If I supply invalid credentials I get a different error, HTTP 401, so it's most likely a different error.