Genesys Cloud for Salesforce SDK Rest

I'm just starting out with using the SDK, so please forgive this newbie question.

I need to add code to a custom Lightning Web Component that pauses all of the current user's conversations when a button is pushed.

The API documentation states that the /api/v2/conversations call requires an authenticated user.

However, when I make this call within Apex:

HttpResponse response = purecloud.SDK.Rest.get('/api/v2/conversations/calls');

The response is:

{"message":"This request requires a user context. Client credentials cannot be used for requests to this resource.","code":"not.a.user","status":400,"contextId":"53073ec3-fe9f-4194-9209-5d366f704dc0","details":[],"errors":[]}

I am logged into Genesys within SF when executing the above statement.

How would I use the SF SDK to call the API to get the information I need?

Hi Mike,

It appears you are calling the REST endpoint with an OAuth token obtained with a client credential grant. The endpoint is rejecting it because it needs the OAuth token from a user token and not a client credential grant.

Thanks,
John

How would I get the user's Genesys OAuth token from within Salesforce Apex code?

You have to use any of the OAuth grants that aren't client credentials: https://developer.genesys.cloud/authorization/platform-auth/. I'm not familiar with how Apex' architecture works, so I'm not sure which grant is most appropriate. There are descriptions at that link that describe which method is best suited for various architectures.

What SDK is this? Can you link me to docs for it? I don't recognize this.

@Mike_Sobczak I tracked down what SDK you're using: SDK in Genesys Cloud for Salesforce - Genesys Cloud Resource Center. This SDK only supports client credentials, which are unable to make API requests that require a user context. You will need to build a custom integration using one of the auth grants from my previous link that's not client credentials to be able to make those requests with a user context. Those flows will require that the user complete an OAuth flow in their browser.

Would the same be said if the agent is already logged and authorized via the embeddable framework (sf for GC)?

It seems to be if we utilize purecloud-for-salesforce-examples/src/Lightning Experience/events-in-salesforce at master · MyPureCloud/purecloud-for-salesforce-examples · GitHub

the above illustration, it seems to me as if that is using auth via the implicit grant from the integraiton. therefore, we can use the users' auth wherever we like on a salesforce page, no?

The embeddable framework uses user-based auth, yes. If that product meets your needs, feel free to use it. My answer above was only about the SDK referenced in the original post.

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