Hey all! I recently configured Postman so that it will automatically pull a new JSON Web Token (JWT) every time you send an API call.
To do this, you set up a variable to store the token, and then add a Pre-Request Script to generate the token using your ClientID and SecretID.
At the top collection level, define a Pre-Request Script as follows:
const tokenUrl = 'https://xxxxxx.api.cloud.sailpoint.com/oauth/token';
const clientId = 'xxxxxxx';
const clientSecret = 'xxxxxx';
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);
});
Update your org, ClientID, and Secret for your Personal Access Token from IDN, and save it.
(Note: You may see an error/warning when you first save this, because the variable has not yet been set, but once you make one API call, it will be fine).
Finally, update the Authorization
tab, and select Bearer Token for Type
, and use the variable {{access_token}}
in the Token
field. For individual API items, set them to “Inherit from parent”