var app_id = pm.variables.get("clientId");
var app_key = pm.variables.get("secret");
var authurl = pm.variables.get("tenant") + "/oauth2/token";
var resource = pm.variables.get("resource");
pm.sendRequest({
url: authurl,
method: 'POST',
header: {
'content-type': 'application/json'
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "client_credentials", disabled: false},
{key: "client_id", value: app_id, disabled: false},
{key: "client_secret", value: app_key, disabled: false},
{key: "resource", value: resource, disabled: false}
]
}
}, function (err, res) {
pm.variables.set("token", res.json().access_token);
});
Under the Authorization tab, choose:
Auth Type: Bearer Token
Token: {{token}}
Save the collection settings.
In Environments, create a new environment and define: