Calling API from Lambda

I'm trying to write a Lambda function that will call the Pure Cloud API. I'm using this example: https://developer.genesys.cloud/authorization/platform-auth/guides/oauth-client-credentials-guide#language=nodejs&step=0 as a basis for my code, but it doesn't hit any of the console log messages, e.g, this one

.then(jsonResponse => {
console.log(jsonResponse);
})

I've been looking at this all day and got nowhere, so any advice gratefully received!

Troubleshooting your AWS infrastructure is outside the scope of this forum, but I would advise to look at the cloudwatch logs for the lambda function to see what it thinks is happening. Check logging for API Gateway or whatever is invoking the lambda to see what it thinks is happening. If you're unable to determine why your lambda function isn't getting invoked, I would suggest posting on the AWS forums or opening a case with AWS support.

So how do I get the list of queues? Here's my code:

let authPromise = function(data) {
return client.loginClientCredentialsGrant(CLIENT_ID, CLIENT_SECRET)
.then(() => {
console.log("Got queues");
return routingApi.getRoutingQueues()})
}

  var p = new Promise(authPromise);

  p.then(console.log("executed")).then(console.log("again"));

  console.log(p);

I'm getting the messages:

executed
again
Promise { }
Result:
{
"statusCode": 200,
"body": "done"
}

I would have thought calling the second "then" would have executed getRoutingQueues and return results, but it's just returning a pending Promise?

I've tried it again adapting the solution to this post About loginClientCredentialsGrant - Platform API - Genesys Cloud Developer Forum.

Still no results being returned:

client.loginClientCredentialsGrant(CLIENT_ID, CLIENT_SECRET)
.then(() => {
routingApi.getRoutingQueues()
.then((data) => {
console.log(getOrganizationsMe success! data: ${JSON.stringify(data, null, 2)});
})
.catch((err) =>
{
console.log("Error", err);
})
});

I would suggest reviewing the JavaScript SDK documentation and looking at some guides to get an idea of how to make an API request.

I've looked at nothing else for the past two days. I've copied examples and posted them directly into the code. Nothing is working.

I've copied this code directly from the documentation:

const client = platformClient.ApiClient.instance;
client.loginClientCredentialsGrant(clientId,clientSecret)
.then(()=> {
// Do authenticated things
})
.catch((err) => {
// Handle failure response
console.log(err);
});

if I add a console.log to where it says //Do authenticate things, nothing appears. It doesn't hit the then or the catch!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.