HTTP 401 APIs > Tutorials > Querying Queue Historical Statistics

I am studying PureCloud API.

<1st>
I begin with "OAuth Client Credentials Login Flow".

I modefied as follows.
1.client_id = "CLIENT_ID" to client_id = "secret mine"
2.client_secret = "CLIENT_SECRET" to client_secret = "secret mine"
3.# Get token
com to jp

I got message. "Failure: 401 - Unauthorized".

I try to read source code and modefied as follows again.
4. # Get roles
com to jp

I got message. "Got roles", "Roles: ...", "Done"

<2nd>
Next, I try to run "Querying Queue Historical Statistics".

I modefied as follows too.
1.client_id = "CLIENT_ID" to client_id = "secret mine"
2.client_secret = "CLIENT_SECRET" to client_secret = "secret mine"
3.# Get token
com to jp
4.# Get "Support" queue by name
routing_api.get_routing_queues(name='Support') to routing_api.get_routing_queues(name='My Queue')

I got message. "Failure: 401 - Unauthorized".

Then I thought difference between <1st> and <2nd> is "Region".
I try to grep "Region", then I find "purecloud_region_hosts.py".

I read Software Development Kit (SDK).
(https://developer.mypurecloud.com/api/rest/client-libraries/index.html)
But I can't find howto change "Region" in Python.
(Only Java and .NET)

How can I run "Querying Queue Historical Statistics".

I found setting environment in " PureCloud API SDK - Python".
(https://developer.mypurecloud.com/api/rest/client-libraries/python/index.html#using_the_library)

region = PureCloudPlatformClientV2.PureCloudRegionHosts.ap_northeast_1
PureCloudPlatformClientV2.configuration.host = region.get_api_host

I got message below.

  • Querying Queue Historical Statistics -

Got token
Traceback (most recent call last):
File "/home/ec2-user/bin/purecloud_v2.58.0.0/ikeda_historical_statistics.py", line 62, in
queue_data = routing_api.get_routing_queues(name='My Queue')
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/apis/routing_api.py", line 2098, in get_routing_queues
callback=params.get('callback'))
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/api_client.py", line 401, in call_api
response_type, auth_settings, callback)
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/api_client.py", line 219, in __call_api
url = self.host + resource_path
TypeError: unsupported operand type(s) for +: 'method' and 'str'

"My Queue" is exist.
I checked "/api/v2/routing/queues/divisionviews" at "https://developer.mypurecloud.jp/developer-tools/#/api-explorer".

How can I run "Querying Queue Historical Statistics".

Hi RedTop,

The get_api_host is a method which means your line should be:

PureCloudPlatformClientV2.configuration.host = region.get_api_host()

Note the parenthesis

EDIT: We'll have the documentation updated for that.

Hi PrinceMerluza

I really appreciate your advice.

Then I add the code into "Querying Queue Historical Statistics"
(https://developer.mypurecloud.com/api/tutorials/analytics-conversation-aggregate-query/?language=python&step=1)

region = PureCloudPlatformClientV2.PureCloudRegionHosts.ap_northeast_1 PureCloudPlatformClientV2.configuration.host = region.get_api_host

But I got Error Message Bellow.
/**********************************************************

  • Querying Queue Historical Statistics -

Got token
Traceback (most recent call last):
File "/home/ec2-user/bin/purecloud_v2.58.0.0/ikeda_historical_statistics_1.py", line 67, in
queue_data = routing_api.get_routing_queues(name='My Queue')
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/apis/routing_api.py", line 2098, in get_routing_queues
callback=params.get('callback'))
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/api_client.py", line 401, in call_api
response_type, auth_settings, callback)
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/api_client.py", line 219, in __call_api
url = self.host + resource_path
TypeError: unsupported operand type(s) for +: 'method' and 'str'
**********************************************************/

And I found another way, "QueueEntityListing get_routing_queues".
(https://developer.inindca.com/api/rest/client-libraries/python/RoutingApi.html#get_routing_queues)

Then I add the code into " get_routing_queues".

region = PureCloudPlatformClientV2.PureCloudRegionHosts.ap_northeast_1 PureCloudPlatformClientV2.configuration.host = region.get_api_host name = 'My Queue' active = True (Because Original code "active = true" get error message)

But I got Error Message Bellow.
/**********************************************************

  • Querying Queue Historical Statistics -

Got token
Traceback (most recent call last):
File "/home/ec2-user/bin/purecloud_v2.58.0.0/ikeda_historical_statistics_2.py", line 79, in
api_response = api_instance.get_routing_queues(page_size=page_size, page_number=page_number, sort_by=sort_by, name=name, active=active, division_id=division_id)
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/apis/routing_api.py", line 2098, in get_routing_queues
callback=params.get('callback'))
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/api_client.py", line 401, in call_api
response_type, auth_settings, callback)
File "/home/ec2-user/bin/purecloud_v2.58.0.0/PureCloudPlatformClientV2/api_client.py", line 219, in __call_api
url = self.host + resource_path
TypeError: unsupported operand type(s) for +: 'method' and 'str'
**********************************************************/

Please tell me the right way to run "Querying Queue Historical Statistics" or "QueueEntityListing get_routing_queues".

Hi PrinceMerluza

I really, really appreciate your advice.

I read your message again, and i try modifiing my code with "()".

I got right responce!!

1 Like

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