I tried to automate my postman test. In first test I should get access token to execute the API call. So I write pre test below. But I am getting 'There was an error in evaluating the Pre-request Script:Error: No data, empty input at 1:1 ^'. I tried commenting last section but it's not worked.
How should I automate this ?
const tokenUrl = 'https://xxxxxxxxxxxx/token';
const clientId = 'xxxxxxxxxxxxxxxx';
const clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const getTokenRequest = {
method: 'POST',
url: tokenUrl,
body: {
mode: 'formdata',
formdata: [
{ key: 'grant_type', value: 'Client Credentials' },
{ key: 'client_id', value: clientId },
{ key: 'client_secret', value: clientSecret }
]
}
};
pm.sendRequest(getTokenRequest, (err, response) => {
const jsonResponse = response.json();
const newAccessToken = jsonResponse.access_token;
pm.variables.set('access_token', newAccessToken);
});