postman bearer token
// 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);
});
Are there any code examples left?
New code examples in category Other