Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PreRequest Script for Postman to get an access token for a resouce using the client credentials flow
var client_id = pm.environment.get("client_id");
var client_sercret = pm.environment.get("client_secret");
var token_endpoint = pm.environment.get("token_endpoint");
var scope = pm.environment.get("scope");
url: token_endpoint,
method: 'POST',
header: {
'Content-Type': 'multipart/form-data',
body: {
mode: 'formdata',
formdata: [
{key: "grant_type" , value: "client_credentials"},
{key: "client_id" , value: client_id},
{key: "client_secret" , value: client_sercret},
{key: "scope" , value: scope}
}, function(err, response) {
const jsonResponse = response.json();
pm.environment.set("access_token", jsonResponse.access_token);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.