Legacy Dev Forum Posts

 View Only

Sign Up

/api/v2/routing/wrapupcodes Connection Timeout

  • 1.  /api/v2/routing/wrapupcodes Connection Timeout

    Posted 06-05-2025 18:25

    mihail | 2023-03-20 12:36:27 UTC | #1

    Hi,

    I am new to using Genesys cloud API's for extracting data and new to Python. I am trying to create a python script which lists all the wrap up codes.

    I put together the below script and running this in VSCode but the results is "ConnectTimeout: HTTPSConnectionPool(host='api.mypurecloud.com', port=443): Max retries exceeded with url: /api/v2/routing/wrapupcodes (Caused by ConnectTimeoutError(, 'Connection to api.mypurecloud.com timed out. (connect timeout=None)'))"

    Below is the python script I am using. It successfully obtains a token. I removed the value for auth_endpoint variable as the forum doesnt allow me to post 2 links.

    import datetime import logging import requests import json import certifi import os from datetime import date

    Define the API endpoint for obtaining an authentication token

    auth_endpoint =

    Set the API key and secret for authentication

    apikey = 'x' apisecret = 'x'

    Set the authentication data for the API request

    authdata = { 'granttype': 'clientcredentials', 'clientid': apikey, 'clientsecret': api_secret, 'Content-Type': 'application/x-www-form-urlencoded' }

    Send a POST request to the authentication endpoint

    authresponse = requests.post(authendpoint, data=auth_data)

    Check if the request was successful

    if authresponse.statuscode == 200: print("good request")

    Extract the access token from the response object

    authtoken = authresponse.json()['accesstoken'] print("Authentication token obtained successfully.") print({authtoken})

    Define the API endpoint for the Conversation Details API

    url = 'https://api.mypurecloud.com/api/v2/routing/wrapupcodes'

    Set the authorization header using the authentication token

    headers = {

    'Authorization': 'Bearer ' + auth_token,

    'Content-Type': 'application/json'

    }

    headers = { "Authorisation": f"Bearer {auth_token}", 'Content-Type': 'application/json' }

    response = requests.get(url, headers=headers) print(response.status_code)

    Check if the request was successful

    if response.status_code == 200:

    Extract the conversation data from the response object

    data = response.json()

    Process the data as desired

    for item in data['conversations']:

    print("all good")

    else:

    If the request was not successful, print the error message

    print("Error retrieving data from Conversation Details API:", response.statuscode) print("Error retrieving data from Conversation Details API:", response.reason) raise ValueError("Error retrieving data from Conversation Details API:",response.statuscode)

    else: print("bad request")

    Any guidance would be greatly appreciated.


    Declan_ginty | 2023-03-20 13:31:06 UTC | #2

    Hi Mihail,

    It looks like your calling the API's directly, it would be easier to use the Python SDK for this. This page explains how to install the Python SDK and then you can use the Python method to get a list of wrap up codes. The api explorer has examples that shows how to use the various API's in the different SDK's. Take a look at the Python example for wrap up codes https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-routing-wrapupcodes.

    Regards, Declan


    mihail | 2023-03-20 14:05:10 UTC | #3

    Hi Declan,

    Thanks for getting back on this. I've installed the python SDK and running into new issues.

    When I try to run the below script, I get a "KeyError" I am also setting the region to euwest1 for Ireland but this fails either way.

    import PureCloudPlatformClientV2 import os from PureCloudPlatformClientV2.rest import ApiException from pprint import pprint

    region = PureCloudPlatformClientV2.PureCloudRegionHosts.euwest1 PureCloudPlatformClientV2.configuration.host = region.getapihost() apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken(os.environ['x'], os.environ['x'])

    authApi = PureCloudPlatformClientV2.AuthorizationApi(apiclient) print(authApi.getauthorizationpermissions())

    Any ideas?

    Thanks in advance, Mihail


    Declan_ginty | 2023-03-20 15:34:35 UTC | #4

    Hi Mihail,

    Would you be able to provide the error message you are getting? Some things to make sure are correct are to make sure the region of the org you are using is the same as the host region you are telling the SDK to use, in your case make sure your org is in eu-west-1. Also make sure you are using the correct oauth client id and secret in the get_client_credentials_token method. In the example above you are setting both the client id and secret to an environment variable call x

    Regards, Declan


    mihail | 2023-03-20 16:30:38 UTC | #5

    Hi Declan,

    Cheers for the details. I updated the script and running into a new error which seems to be a bit more meaningful but I can't figure out why.

    The HTTP Response body message is saying that the client is invalid, client not found. I don't understand why as I am using the the Client credentials directly from the Admin portal which has all the relevant access.

    I am setting the region to euwest1 as my org is based in Ireland?!

    Error details below Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 20 Mar 2023 16:19:18 GMT', 'Content-Type': 'application/json', 'Content-Length': '99', 'Connection': 'keep-alive', 'Inin-Correlation-Id': '95f2113c-e8ee-4648-4af4-0245b55e0d79', 'Strict-Transport-Security': 'max-age=7776000', 'Vary': 'Accept-Encoding'}) HTTP response body: {"error":"invalidclient","description":"client not found","errordescription":"client not found"}

    updated script import PureCloudPlatformClientV2 import os from PureCloudPlatformClientV2.rest import ApiException from pprint import pprint import datetime import logging import requests import json import certifi import os from datetime import date

    region = PureCloudPlatformClientV2.PureCloudRegionHosts.euwest1 PureCloudPlatformClientV2.configuration.host = region.getapihost()

    GENESYSCLOUDCLIENTID = 'my client id ' GENESYSCLOUDCLIENTSECRET = 'my client secret'

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken('GENESYSCLOUDCLIENTID','GENESYSCLOUDCLIENTSECRET') print(apiclient.access_token)

    authApi = PureCloudPlatformClientV2.AuthorizationApi(apiclient) print(authApi.getauthorizationpermissions())

    Any thoughts on this one?

    Thanks, Mihail


    Declan_ginty | 2023-03-20 17:21:31 UTC | #6

    Hi Mihail,

    The reason for your error is because the authentication has failed. We always need to authenticate ourselves whenever we use any of the SDK's using either OAuth Client Id and Secret or with an access token. In your code above there's a slight problem, you are not passing GENESYS_CLOUD_CLIENT_ID and GENESYS_CLOUD_CLIENT_SECRET to the get_client_credentials_token method, you are actually passing two strings with the values GENESYS_CLOUDCLIENTID and GENESYSCLOUDCLIENT_SECRET so that's why the authentication is failing. Instead try:

    apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(GENESYS_CLOUD_CLIENT_ID,GENESYS_CLOUD_CLIENT_SECRET)

    Regards, Declan


    mihail | 2023-03-22 12:28:52 UTC | #7

    Thanks Declan,

    I am running into proxy issues at the moment so will keep hammering at this. Thanks for your help.

    Regards, Mihail


    John_Carnell | 2023-03-27 15:35:33 UTC | #9


    This post was migrated from the old Developer Forum.

    ref: 18997