Hi,
I have been trying to use a modification of the get/api/v2/conversations/calls API where the code as follows:
const platformClient = require('purecloud-platform-client-v2');
const client = platformClient.ApiClient.instance;
client.setEnvironment(platformClient.PureCloudRegionHosts.ap_southeast_2);
const CLIENT_ID = " ";
const CLIENT_SECRET = " ";
let organizationApi = new platformClient.OrganizationApi();
//Authenticate with Genesys Cloud
client.loginClientCredentialsGrant(CLIENT_ID, CLIENT_SECRET)
.then(() => {
organizationApi.getOrganizationsMe()
.then((data) => {
// console.log(`getOrganizationsMe success! data: ${JSON.stringify(data, null, 2)}`);
client.setAccessToken(data);
})
.catch((err) => {
console.log('There was a failure calling getOrganizationsMe');
console.error(err);
});
}).catch((err) => {
console.log('There was a failure calling loginClientCredentialsGrant');
console.error(err);
});
let apiInstance = new platformClient.ConversationsApi();
// Get active call conversations for the logged in user
apiInstance.getConversationsCalls()
.then((data) => {
console.log(`getConversationsCalls success! data: ${JSON.stringify(data, null, 2)}`);
})
.catch((err) => {
console.log("There was a failure calling getConversationsCalls");
console.error(err);
});
I have had an issue set auth token bit where I would use client.loginClientCredentialsGrant(CLIENT_ID, CLIENT_SECRET) and then run the apiInstance.getConversationsCalls(). This will return a 401 with a message "No authentication bearer token specified in authorization header". The developer guide has stated in the API explorer
// Manually set auth token or use loginImplicitGrant(...) or loginClientCredentialsGrant(...)
client.setAccessToken("your_access_token");
Not sure what I've done wrong in setting the auth token. Any help is appreciated. Thanks.