Skip to content

Instantly share code, notes, and snippets.

@moyarich
Last active January 14, 2020 16:37
Show Gist options
  • Save moyarich/3bae738247825a0232d9c868b6aa4f93 to your computer and use it in GitHub Desktop.
Save moyarich/3bae738247825a0232d9c868b6aa4f93 to your computer and use it in GitHub Desktop.
Yotpo Authentication - get bearer request token for use with postman
/**
* Yotpo Authentication This endpoint uses your Yotpo API Key and API Secret to generate the API utoken necessary to authenticate most of Yotpo's API calls.
* Note that utokens are invalidated upon logging out of the Yotpo system.
* As such, we recommend generating a new utoken for every API call.
*
* https://apidocs.yotpo.com/reference#yotpo-authentication
*
* Sample - pre request script taken from
*
* https://gist.github.com/bcnzer/073f0fc0b959928b0ca2b173230c0669
*/
const OauthTokenRequest = {
url: pm.environment.get("YOTPO_API_ROOT_URL") + "oauth/token",
method: "POST",
header: "Content-Type:application/json",
body: {
mode: "application/json",
raw: JSON.stringify({
client_id: pm.environment.get("YOTPO_APIKEY"),
client_secret: pm.environment.get("YOTPO_APISECRET"),
//audience: pm.environment.get('my_audience'),
grant_type: "client_credentials"
})
}
};
console.log(
"OauthTokenRequest:\n\n",
JSON.stringify(OauthTokenRequest, null, 4)
);
pm.sendRequest(OauthTokenRequest, function(err, res) {
console.log(err ? err : res.json());
if (err === null) {
const responseJson = res.json();
console.log("Saving the Yotpo Bearer token");
console.log(JSON.stringify(responseJson, null, 4));
pm.environment.set("YOTPO_BEARER_TOKEN", responseJson.access_token);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment