Suite script sample to get Access Token from Amazon Seller Central

The below code can be used to retrieve the Access Token from Amazon Seller Central. The token will be returned in the response body of the request.

The refreshToken, clientId and clientSecret can be retrieved from the developer app created in the Amazon Developer Central.

function getAccessToken(){
   
        let refreshToken="xxxxxxxxxxxx";
        let clientId="xxxxxxxxxx";
        let clientSecret="xxxxxxxxxxxx";
        let amazonApiUrl = 'https://api.amazon.com/auth/o2/token';

        // Construct the payload for the request
        let payload = {
            grant_type: 'refresh_token',
            refresh_token: refreshToken,
            client_id: clientId,
            client_secret: clientSecret
        };

        // Make the HTTP POST request
        let response = https.post({
            url: amazonApiUrl,
            body: payload,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });
        if(response.code===200){
            let responseObject=JSON.parse(response.body);
            let token=responseObject.access_token;
            return token;
        }

}

Leave a comment

Your email address will not be published. Required fields are marked *