Jeremy_Gillip | 2019-06-20 21:23:30 UTC | #1
I am working in Node.js and am able to get a POST request to get a token ok in the format below
{ "accesstoken": "9s1jsCNxpF1swHGQGmXXZhgpQTPpxII6BYAwtlNuEUxD0614nDBmMcGLs2zzTBJeJQJZbgHeZ3QviEoXXXXXX", "tokentype": "bearer", "expires_in": 86399 }
When i then pass that to another app in Node using the SDK function getMe(yourAccessToken) {
platformClient.ApiClient.instance.setAccessToken(yourAccessToken); / let apiInstance = new platformClient.TokensApi(); apiInstance.getTokensMe() .then((data) => { console.log(getTokensMe success! data: ${JSON.stringify(data, null, 2)}); }) .catch((err) => { console.log('There was a failure calling getTokensMe'); //console.error(err); }) } i get the error
body: { status: 401, code: 'authentication.required', message: 'No authentication bearer token specified in authorization header. },
from the SDK article located https://developer.mypurecloud.com/api/rest/client-libraries/javascript/TokensApi.html#getTokensMe i was hoping that i just pass the variable that has the token and that hosts it. Let me down gently if i am missing a step :)
Angalfaria | 2019-06-21 08:45:35 UTC | #2
Nice token format. It's very useful more than what I aspect. Thanks
tim.smith | 2019-06-21 12:52:13 UTC | #3
I just put together a quick test app for this and it's working correctly. There is some issue in your code that's causing the auth token not to be set correctly.
const platformClient = require('purecloud-platform-client-v2');
const client = platformClient.ApiClient.instance;
const yourAccessToken = 'xxx';
client.setAccessToken(yourAccessToken);
let apiInstance = new platformClient.TokensApi();
apiInstance
.getTokensMe()
.then((data) => {
console.log(`getTokensMe success! data: ${JSON.stringify(data, null, 2)}`);
})
.catch((err) => {
console.log('There was a failure calling getTokensMe');
console.error(err);
});
Jeremy_Gillip | 2019-06-21 13:07:25 UTC | #4
Thank you for checking. Should the yourAccessToken be just the entire array or just the line "access_token": "9s1jsCNxpF1swHGQGmXXZhgpQTPpxII6BYAwtlNuEUxD0614nDBmMcGLs2zzTBJeJQJZbgHeZ3QviEoXXXXXX",
tim.smith | 2019-06-21 13:08:51 UTC | #5
The response from the POST endpoint you're referring to is a JSON object. Only use the value of the access_token property.
Jeremy_Gillip | 2019-06-21 13:09:17 UTC | #6
Got it thank you.
Jeremy_Gillip | 2019-06-21 13:13:17 UTC | #7
and its working. could have sworn i tried that combo yesterday. Thank you tim.smith as always.
system | 2019-07-22 13:13:18 UTC | #8
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 5395