Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
let userSecret = "your_user_secret";
let clientSecret = "your_client_secret";
let host_url = 'your_host_url';
let scope = 'your_app_scope';
let toEncode = userSecret +":"+ clientSecret;
toEncode = btoa(toEncode);
pm.environment.set("auth_token", toEncode);
pm.environment.set("host_url", host_url);
pm.environment.set("accessToken", "");
//edit URL to be the one of the token generator
const echoPostRequest = {
url: 'https://'+host_url+'/oauther/oauth2/token',
method: 'POST',
header: {
'Host': host_url,
'Authorization' : 'Basic ' + toEncode
body: {
mode: 'raw',
raw: 'grant_type=client_credentials&scope=' + scope
pm.sendRequest(echoPostRequest, function (err, response) {
let respJson = response.json();
if(respJson.access_token) {
let access_token = respJson.access_token;
pm.environment.set('accessToken', access_token);
pm.test("Access token available and saved.")
} else {
pm.test("Pre-script failure", function() {
throw new Error("Access token missing from response.");
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.