Genesys Cloud - Main

 View Only
Discussion Thread View
  • 1.  Getting 401 error with API calls

    Posted 08-11-2022 20:55
    Hi all, 

    Sorry i'm a noob with getting this to work.  We have a couple of hundred of external contacts in our purecloud and we've tasked one of our clerical people to add the fax numbers in to help with the workflow.  I had invisioned being able to export all the contacts, add the fax numbers via a lookup table in excel, then importing them back in.  Found theres a import, but no export.

    Someone advised I could via the API, so I setup an OAuth app, with the grant type setup as client credentials and the rolls set to master admin.

    I can request a token via a POST call to https://login.mypurecloud.com.au/oauth/token and the body set to grant_type=client_credentials

    when I try to call: api_response = api_instance.get_externalcontacts_contacts(page_size=999)
    I get the error: 
    PureCloudPlatformClientV2.rest.ApiException: (401)
    Reason: Unauthorized
    HTTP response body: {"message":"Invalid login credentials.","code":"bad.credentials","status":401,"contextId":"f9aa9e82-fbd1-48f2-b0da-02bb243f8126","details":[],"errors":[]}

    Any ideas why I'm getting the 401 error?
    #Integrations
    #PlatformAdministration
    #SystemAdministration

    ------------------------------
    Andrew Casey
    Benson Radiology
    ------------------------------


  • 2.  RE: Getting 401 error with API calls

    Posted 08-12-2022 00:14
    Hi Andrew

    Not sure myself but one thing I will say is don't assume that just because the role says "master admin" that it actually has all the permissions for things.

    ------------------------------
    Vaun McCarthy
    ------------------------------



  • 3.  RE: Getting 401 error with API calls

    Posted 08-15-2022 09:02
    I'm assuming your tenant is in Asia Pacific (Sydney)?

    Have you taken a look at https://developer.genesys.cloud/platform/api/postman ?

    You'll need to authenticate with Basic Auth and the client ID and secret.


    ------------------------------
    Bert Barrez
    Sedgwick Claims Management Services, Inc.
    ------------------------------



  • 4.  RE: Getting 401 error with API calls

    Posted 08-15-2022 19:52
    Hi Bert,

    I'll check out postman, thanks for that.  And yes, i'm logging into the Sydney area.

    I've gone through the login process and got myself a token before I called the API, just via a curl:

    curl -d "grant_type=client_credentials" -H "Host: login.mypurecloud.com.au" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic [redacted]" -X POST https://login.mypurecloud.com.au/oauth/token

    and it does respond back with an access token:

    {"access_token":"[redacted]","token_type":"bearer","expires_in":86399}

    The full code i'm using is:

    import time
    import PureCloudPlatformClientV2
    from PureCloudPlatformClientV2.rest import ApiException
    from pprint import pprint
    # Configure OAuth2 access token for authorization: PureCloud OAuth
    PureCloudPlatformClientV2.configuration.access_token = 'token from curl command'
    api_instance = PureCloudPlatformClientV2.ExternalContactsApi()
    api_response = api_instance.get_externalcontacts_contacts(page_size=999)
    ​

    and it's right at this point I get the bad credentials error.



    ------------------------------
    Andrew Casey
    Benson Radiology
    ------------------------------



  • 5.  RE: Getting 401 error with API calls

    Posted 08-16-2022 08:05
    Silly question; does the oauth setup for this authentication have roles assigned (to all divisions)?

    PureCloudPlatformClientV2.configuration.access_token = 'token from curl command'​

    You mean you're using the variable access_token here?

    PureCloudPlatformClientV2.configuration.access_token = access_token


    ------------------------------
    Bert Barrez
    Sedgwick Claims Management Services, Inc.
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources