Skip to content

Instantly share code, notes, and snippets.

@TaylorAckley
Created December 11, 2018 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaylorAckley/ab84283e50f400dd4cee973b18a56d95 to your computer and use it in GitHub Desktop.
Save TaylorAckley/ab84283e50f400dd4cee973b18a56d95 to your computer and use it in GitHub Desktop.
Postman Pre-Request Script
// For usage in Postman as Pre-Request Script to get token.
// Requires a environment file with 'client', 'secret', 'url' and 'authorization' key/value pairs. (leave the authorization key blank)
pm.sendRequest({
url: pm.environment.get("url") + '/auth/token',
method: 'POST',
header: {
"content-type": "application/x-www-form-urlencoded"
},
body: {
mode: 'urlencoded',
urlencoded: [
{key: "grant_type", value: "client_credentials", disabled: false},
{key: "client_id", value: pm.environment.get("client"), disabled: false},
{key: "client_secret", value: pm.environment.get("secret"), disabled: false}
]
}
}, function (err, res) {
console.log(err ? err : res.json());
pm.environment.set("authorization", "Bearer " + res.json().access_token);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment