Skip to content

Instantly share code, notes, and snippets.

@sdrycroft
Created December 2, 2017 15:15
Show Gist options
  • Save sdrycroft/a4965d1b393b68999f9a2f757eee379a to your computer and use it in GitHub Desktop.
Save sdrycroft/a4965d1b393b68999f9a2f757eee379a to your computer and use it in GitHub Desktop.
if((Date.now() / 1000 | 0) > pm.environment.get("oauthTokenExpires")) {
pm.sendRequest({
url: "{{baseUrl}}/token",
method: 'POST',
header: 'Content-Type: application/json',
body: {
mode: 'raw',
raw: JSON.stringify({
grant_type: "client_credentials",
client_id:"{{clientIdentifier}}",
client_secret:"{{clientSecret}}"
})
}
}, function (err, response) {
pm.environment.set("oauthTokenExpires", (Date.now() / 1000 | 0) + response.json().expires_in)
pm.environment.set("oauthToken", response.json().access_token);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment