Hello Community,
I am seeking some guidance or help on this problem. I am an intern working on an API project. To begin I am tasked with getting an API running from the API explorer on VS Code. I keep running into the problem with authorization using the Bearer token. I have got the API to run using cURL. However, I want it to run on JS. When I put in my Bearer token I am getting an error message stating:
"message: 'No authentication bearer token specified in authorization header.',
code: 'authentication.required',
status: 401,
contextId: '9e326059-38fc-43f1-8f0a-7c92ca91ef46',
details: [],
errors: []"
I used cURL to create a Bearer token and used the token in JS but it still gives the same error message.
Then I changed the code instead using the Bearer token to Credit Credentials Grant login type. Still says the same error message.
Questions:
- Can you run a Genesys API from VS Code?
- Is there a language that will allow me to edit an API?
Below I have posted the API's code I am trying to run. (On line 7, I left the 'access token' part blank for security reasons 'client.setAccessToken("your_access_token" );
const platformClient = require("purecloud-platform-client-v2");
const client = platformClient.ApiClient.instance;
client.setEnvironment(platformClient.PureCloudRegionHosts.us_east_1); // Genesys Cloud region
// Manually set auth token or use loginImplicitGrant(...) or loginClientCredentialsGrant(...) or loginPKCEGrant(...)
client.setAccessToken("your_access_token");
let apiInstance = new platformClient.GroupsApi();
let opts = {
"pageSize": 25, // Number | Page size
"pageNumber": 1, // Number | Page number
"id": ["id_example"], // [String] | id
"jabberId": ["jabberId_example"], // [String] | A list of jabberIds to fetch by bulk (cannot be used with the id parameter)
"sortOrder": "ASC" // String | Ascending or descending sort order
};
// Get a group list
apiInstance.getGroups(opts)
.then((data) => {
console.log(`getGroups success! data: ${JSON.stringify(data, null, 2)}`);
})
.catch((err) => {
console.log("There was a failure calling getGroups");
console.error(err);
});
I have the clientId and clientSecret, I changed the line of code
'client.setAccessToken("your_access_token"); to
client.loginClientCredentialsGrant("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
.then(() => {
const apiInstance = new platformClient.GroupsApi();
I still get the error message.
Our end goal is to hopefully find or create an API that runs reports on a schedule or an API that can create reports of what the department is asking for.
Example:
Help Desk wants an API that can report how many calls came in for the week or month, which calls either failed, disconnected, did not answer etc.
#PlatformAPI------------------------------
Alberto Hernandez
------------------------------