Authentication Login using Python code for Conversations API

Hi,

I am trying to use the Conversations API to send an SMS message. When I login using a non user account, the message indicates:

PureCloudPlatformClientV2.ConversationsApi(apiclient)
"This request requires a user context. Client credentials cannot be used for requests to this resource."

I have a user account which works using the SDK directly from the UI. I don't know how to login using these credentials. I believe I need to do this:

apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_saml2bearer_token(
"me@companyName.com",
"password",
"companyName",
samlAssersion)

We don't use SSO, thus no SAML Assertion. Each user has their own login credentials that are set outside the company login. What do I use for the samlAssertion? Is there a different way I need to login or a different user type that can access the Conversations API without SSO.

Thanks,
Greg

You can find documentation on the authorization methods here: https://developer.genesys.cloud/authorization/platform-auth/. If you're not using SSO and want a user-based grant, you would use the implicit, PKCE, or auth code grant.

Because Python isn't a web-based language, you will have to embed a browser in your application or a local web server to pop the page open in a browser to handle the OAuth flow. Users can only authorize using the Genesys Cloud login page in a browser or SAML.

HI Tim,

Thank you for the response. I can login and can access the headers. I now need to do this

PureCloudPlatformClientV2.ConversationsApi(apiclient);

But since I did not use the api_client to login, what do I put instead of the apiclient so the platform will know I am authenticated.

Thanks,
Greg

It's not explicitly documented in the SDK's auth section, but you just set it on the api client (e.g. apiClient.access_token = "xxxxxx"). You can see how it's initialized in the constructor here: platform-client-sdk-python/build/PureCloudPlatformClientV2/api_client.py at master · MyPureCloud/platform-client-sdk-python · GitHub

I set the access_token as shown here

apiclient = PureCloudPlatformClientV2.api_client.ApiClient()
apiclient.access_token = response.cookies.get_dict()['ININ-Auth-Session']

Getting
HTTP response body: {"message":"Invalid login credentials.","code":"bad.credentials","status":401,"contextId":"40a44075-049c-4af1-a172-037541200f1f","details":[],"errors":[]}

I tried adding my client_id and client_secret to the apiclient. Same result.

I also see an ININ-Correlation-Id on the response from the login. Not sure which values I need to use where.