Created
December 11, 2018 18:15
-
-
Save TaylorAckley/ab84283e50f400dd4cee973b18a56d95 to your computer and use it in GitHub Desktop.
Postman Pre-Request Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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