Call to get list of queues does not return any data

Hi,

I am new to the PureCloud environment. We intend to acquire the PureCloud data into our data warehouse environment. The following python code was written to test the calls to the API. Unfortunately the code executes fine but I don't get any data. If I execute the API call in the API Explorer I do get the expected result. Help much appreciated.

import base64, sys, requests
import json
import time
import pprint
    
# Configure OAuth2 access token for authorization: PureCloud OAuth

# OAuth when using Client Credentials
client_id = "XXXX"  
client_secret = "XXX"
authorization = base64.b64encode(bytes(client_id + ":" + client_secret, "ISO-8859-1")).decode("ascii")

# Prepare for POST /oauth/token request
auth_request_headers = {
    "Authorization": f"Basic {authorization}",
    "Content-Type": "application/x-www-form-urlencoded"
}
auth_request_body = {
    "grant_type": "client_credentials"
}

# Get token
print("before token")
auth_response = requests.post("https://login.mypurecloud.com.au/oauth/token", data=auth_request_body, headers=auth_request_headers)

print("after token")
# Check response
if auth_response.status_code == 200:
    print("Got token")
else:
    print(f"Failure: { str(auth_response.status_code) } - { auth_response.reason }")
    sys.exit(auth_response.status_code)

access_token = auth_response.json()["access_token"]
print(access_token)
requestHeaders = {
"Content-Type": "application/json",
"Authorization": "bearer" + " " + str(access_token)
}

print("-------------------------------------------------------------")
print("- Listing all queues -")
print("-------------------------------------------------------------")


response = requests.get('https://api.mypurecloud.com.au/api/v2/routing/queues?pageSize=27', headers=requestHeaders)
if response.status_code == 200:
   print("Got Queues")
   responseJson = response.json()
   pprint.pprint(json.dumps(responseJson, indent=6))
else:
   print ('Failure: ' + str(response.status_code) + ' - ' + str(response.reason))
   sys.exit(response.status_code)

The result that I get when I run the above script is as follows:

/usr/lib/python3/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.25.3) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
before token
after token
Got token
-------------------------------------------------------------
- Listing all queues -
-------------------------------------------------------------
Got Queues
('{\n'
 '      "entities": [],\n'
 '      "pageSize": 27,\n'
 '      "pageNumber": 1,\n'
 '      "total": 0,\n'
 '      "firstUri": "/api/v2/routing/queues?pageSize=27&pageNumber=1",\n'
 '      "selfUri": "/api/v2/routing/queues?pageSize=27&pageNumber=1",\n'
 '      "lastUri": "/api/v2/routing/queues?pageSize=27&pageNumber=1",\n'
 '      "pageCount": 0\n'
 '}')

Is there any reason you're not using the Python SDK?

If you're getting a successful response with no results, my guess is that your client credentials don't have appropriate permissions for divisions. See Fine Grained Access Control and the resource center link at the top of the page for more info about divisions.

Hi Tim,

Thanks for the response. The issue was resolved by generating a new secret key.

I have got another program that uses the SDK and now with the new key works very well.

Samir

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