0

I'm a newbie in postman. I'm trying to automate the process of refreshing Access token using pre-request script of postman as mentioned in the below document

Click here

Pre-request Code:

     let tokenUrl = 'https://oauth.brightcove.com/v4/access_token';
     let clientId = '-----------------------------------------';
      let clientSecret ='---------------------------------------';
     let getTokenRequest = {
     method: 'POST',
     url: tokenUrl,
    auth: {
    type: "basic",
    basic: [
        { key: "username", value: clientId },
        { key: "password", value: clientSecret }
    ]
},
body: {
    mode: 'urlencoded',
    urlencoded: [
        { key: 'grant_type', value: 'client_credentials' }
    ]
}
};

  pm.sendRequest(getTokenRequest, (err, response) => {
let jsonResponse = response.json(),
    newAccessToken = jsonResponse.access_token;

console.log({ err, jsonResponse, newAccessToken })

pm.environment.set('accessToken', newAccessToken);
pm.variables.set('accessToken', newAccessToken);
 });

While running the api, postman console shows the following error

{{err: null, jsonResponse: {…}, newAccessToken: undefined} err: null jsonResponse: {…} error: "invalid_client" error_description: "The "client_id" parameter is missing, does not name a client registration that is applicable for the requested call, or is not properly authenticated." newAccessToken: undefined

Access Token API Documentation

Stuck with this error for almost 4-5 hrs. Can anyone tell me what's the issue here?

Jijith
  • 55
  • 1
  • 2
  • 8

0 Answers0