Legacy Dev Forum Posts

 View Only

Sign Up

Authentication Login using Python code for Conversations API

  • 1.  Authentication Login using Python code for Conversations API

    Posted 06-05-2025 18:09

    Greg_Walters1 | 2024-04-04 13:47:19 UTC | #1

    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.apiclient.ApiClient().getsaml2bearer_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


    tim.smith | 2024-04-04 13:51:41 UTC | #2

    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.


    Greg_Walters1 | 2024-04-04 15:24:37 UTC | #3

    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


    tim.smith | 2024-04-04 15:46:59 UTC | #4

    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: https://github.com/MyPureCloud/platform-client-sdk-python/blob/master/build/PureCloudPlatformClientV2/api_client.py#L96


    Greg_Walters1 | 2024-04-04 16:25:59 UTC | #5

    I set the access_token as shown here

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient() apiclient.accesstoken = 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 clientid and clientsecret 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.


    system | 2024-05-05 16:26:41 UTC | #6

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


    This post was migrated from the old Developer Forum.

    ref: 25560