Answers for "postman set token from response"

0

postman set token from response

// Add to collection pre scripts
// Also don’t forget to set auth in endpoint as {{access_token}}

let tokenUrl = 'Your url to get token';
let email = 'Your email';
let password = 'Your password';

if (pm.environment.name === 'Your env') {
    tokenUrl = 'Another env token url';
}

const getTokenRequest = {
  method: 'POST',
  url: tokenUrl,
  body: {
      mode: 'formdata',
      formdata: [
          { key: 'email', value: email },
          { key: 'password', value: password }
      ]
  }
};

pm.sendRequest(getTokenRequest, (err, response) => {
  const jsonResponse = response.json();
  const newAccessToken = jsonResponse.data.token;
  pm.variables.set('access_token', newAccessToken);
});
Posted by: Guest on June-16-2021

Browse Popular Code Answers by Language