Error 401 - Unathourized

Hi team.
I am trying to access GET API, using following Python Code:

import PureCloudPlatformClientV2

from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint

region = PureCloudPlatformClientV2.PureCloudRegionHosts.eu_west_2
PureCloudPlatformClientV2.configuration.host = region.get_api_host()
apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token('',
'
******')

RoutingApi = PureCloudPlatformClientV2.AuthorizationApi(apiclient)

create an instance of the API class

api_instance = PureCloudPlatformClientV2.RoutingApi();
page_number = 1
page_size = 25
sort_order = 'asc'
name = 'name_example'
id = ['id_example']
division_id = ['division_id_example']
peer_id = ['peer_id_example']
has_peer = True

try:
# Get list of queues.
api_response = api_instance.get_routing_queues(page_number=page_number, page_size=page_size, sort_order=sort_order, name=name, id=id, division_id=division_id, peer_id=peer_id, has_peer=has_peer)
pprint(api_response)
except ApiException as e:
print("Exception when calling RoutingApi->get_routing_queues: %s\n" % e)

it keeps giving me an error

Exception when calling RoutingApi->get_routing_queues: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '201', 'Connection': 'keep-alive', 'Date': 'Wed, 11 Oct 2023 06:57:12 GMT', 'ININ-Correlation-Id': '40f27941-f5f4-4082-84d3-6f2978b2782d', 'Strict-Transport-Security': 'max-age=600; includeSubDomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 828a61ebc3af4e0465a5577a4c08af7a.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'ARN54-C1', 'X-Amz-Cf-Id': 'WpHpy7oJas9kYXrOqPO4Ahxsy5KWRbL9rxSyFhoFMgBa_GGf_uu12g=='})
HTTP response body: {"message":"No authentication bearer token specified in authorization header.","code":"authentication.required","status":401,"contextId":"40f27941-f5f4-4082-84d3-6f2978b2782d","details":[],"errors":[]}
START RequestId: 8734dfae-ecbe-42d8-b159-0aa2261b9d83 Version: $LATEST
[ERROR] Runtime.HandlerNotFound: Handler 'lambda_handler' missing on module 'lambda_function'
Traceback (most recent call last):END RequestId: 8734dfae-ecbe-42d8-b159-0aa2261b9d83

Please suggest.
Thank you.

Hi

Are you setting the RoutingApi correct ?

Two pieces of code you can check this

PureCloudPlatformClientV2.AuthorizationApi(apiclient). --> This is correct way to get Api reference but here you used AuthorizationApi so you would get authApi instance not routingApi

api_instance = PureCloudPlatformClientV2.RoutingApi(); You are not sending the apiclient argument for this. Did you try api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient) ?

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