Trying to read historical data from the tool

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
apiClient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(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'

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.

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

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

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.

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&step=1

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.api_client.ApiClient().get_client_credentials_token("aaaa-aaa-aa", "bbbb-bbb-bbbb")

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.

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.

Could you post the new error message?

Hi Prince,

Below is the error message we got,

Exception when calling RoutingApi->get_routing_queues: {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."}

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.

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?

Use the Analytics APIs to retrieve historical information.

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