Legacy Dev Forum Posts

 View Only

Sign Up

Trying to read historical data from the tool

  • 1.  Trying to read historical data from the tool

    Posted 06-05-2025 18:08

    Abhijeet | 2020-01-21 15:38:02 UTC | #1

    Hello,

    I tried the sample code as it is on https://developer.mypurecloud.com/api/tutorials/analytics-conversation-aggregate-query/?language=python&step=1 for my client token ,however i got below error,

    Traceback (most recent call last): File "C:/PythonCode/purecloud/purecolud1.py", line 20, in <module> apiClient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken(os.environ['abf46b13-febc-4345-af9d-fdd61afrd536'], os.environ['HANDLE CLIENT SECRETS LIKE PASSWORDS']) File "C:\Python\lib\os.py", line 678, in getitem raise KeyError(key) from None KeyError: 'abf46b13-febc-4345-af9d-fdd61afrd536'


    tim.smith | 2020-01-21 15:40:30 UTC | #2

    Please regenerate your client secret immediately. By posting it publicly on the forum, you have compromised your org.

    os.environ[""] is python's way of retrieving environment variables. PURECLOUD_CLIENT_ID and PURECLOUD_CLIENT_SECRET are the names of those variables. You should either set those environment variables so they're available to the application or hardcode them into your application.


    Abhijeet | 2020-01-22 06:39:33 UTC | #3

    I did not shared the original keys out here , they are dummy keys.

    As suggested by you I will set the PURECLOUDCLIENTID and PURECLOUDCLIENTSECRET variables first and will pass them to os.environ[" "] hope this will work.


    Abhijeet | 2020-01-22 12:58:35 UTC | #4

    tim.smith, post:2, topic:6915
    PURECLOUDCLIENTSECRET

    Hi Tim,

    I tried hard coding the variables with the values as suggested above. However I got the same error again.

    What type of clientid and client secret keys we need to generate ? I just want to cross verify the keys once.


    tim.smith | 2020-01-22 17:25:41 UTC | #5

    Abhijeet, post:4, topic:6915
    What type of clientid and client secret keys we need to generate ? I just want to cross verify the keys once.

    https://help.mypurecloud.com/articles/create-an-oauth-client/


    Abhijeet | 2020-01-24 10:14:54 UTC | #6

    HI tim,

    We tried to make a role by selecting "Developer" as role and utilized those keys. However we got the same error as posted above. Can you please suggest where we are getting it wrong.

    We are trying to implement sample code given below using our creds. https://developer.mypurecloud.com/api/tutorials/analytics-conversation-aggregate-query/?language=python&amp;step=1


    anon28885283 | 2020-01-24 14:10:48 UTC | #7

    If it's just for testing purposes could you try replacing the entire

    os.environ['xxxx']

    with just the the hardcoded id and secret? Just so you could run the sample.

    Ex:

    apiClient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken("aaaa-aaa-aa", "bbbb-bbb-bbbb")


    tim.smith | 2020-01-24 16:08:20 UTC | #8

    Abhijeet, post:6, topic:6915
    we got the same error as posted above.

    Abhijeet, post:1, topic:6915
    File "C:/PythonCode/purecloud/purecolud1.py", line 20, in apiClient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken(os.environ['abf46b13-febc-4345-af9d-fdd61afrd536'], os.environ['HANDLE CLIENT SECRETS LIKE PASSWORDS'])

    If you're getting this same error, you haven't updated your code to either hardcode the client ID and secret or pull it from the named environment variables. You'll have to update this line of code to get different behavior. If you've updated your code and that that's not literally the error you're getting anymore, please share the new error.


    Abhijeet | 2020-01-30 11:39:28 UTC | #9

    Hi Prince,

    I have replaced the entire os.environ['xxx'] and it responded with exception about authorization issue. What sort of authorization is needed? The provided client id and token have give developer role.


    anon28885283 | 2020-01-30 11:47:11 UTC | #10

    Could you post the new error message?


    Abhijeet | 2020-01-30 12:06:32 UTC | #11

    Hi Prince,

    Below is the error message we got,

    Exception when calling RoutingApi->getroutingqueues: {e} (403) Reason: Forbidden HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '106', 'Connection': 'keep-alive', 'Date': 'Thu, 30 Jan 2020 12:04:31 GMT', 'inin-ratelimit-count': '1', 'inin-ratelimit-allowed': '300', 'inin-ratelimit-reset': '60', 'ININ-Correlation-Id': '85121d34-d009-4c87-93e6-28f851f80ecf', 'Strict-Transport-Security': 'max-age=600; includeSubDomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 80d333a7c8f87we71eecc760dbcee2d6.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'ORD52-C2', 'X-Amz-Cf-Id': 'AUuuDIOvpfZXiTgRvtjXfczAPACu8xf57mtH4Pb7W7GFbRwmGn9TKQ=='}) HTTP response body: {"status":403,"code":"not.authorized","message":"You are not authorized to perform the requested action."}


    anon28885283 | 2020-01-30 12:18:31 UTC | #12

    The Developer role just gives you access to read/write access to OAuth clients.

    You want to at least add the 'Engage Supervisor' or it might be called 'PureCloud Supervisor' role in your Client Credentials. If in doubt, you can add the 'Master Admin' to gain access to almost all API. Needless to say, you may want to identify and use stricter roles in production as best practice.


    Abhijeet | 2020-01-30 12:47:04 UTC | #13

    Thanks the sample code started responding with data, now we are looking for our historical records from the new application, can we get the old data from here?


    tim.smith | 2020-01-30 16:14:41 UTC | #14

    Use the Analytics APIs to retrieve historical information.


    system | 2020-03-01 16:14:42 UTC | #15

    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: 6915