How to i loop through the Genesys regions without getting the invalid login creds issue

I am facing an Invalid login credentials issue when i am trying to get the data from the PureCloudPlatformClientV2 sdk.
The credential works fine when I run the run for the regions individually ,but fails when I try to run them in a loop ( The first region in the loop works, the rest of them fail). I believe this is happing due to config getting saved in the cache. I tried to do the reimport of library but that didn't help. Is there way to clear the cache ?

Here is what happening when running in loop -

Here is the code -

i
def get_dialer_queue(region,pureCloudAPI,clientID,clientSecret,DbConnStr):

#Reloading the Genesys Module
importlib.reload(PureCloudPlatformClientV2)

table_name ='Staging_Dialer_Queues'
PureCloudPlatformClientV2.configuration.host = pureCloudAPI
logging.info(PureCloudPlatformClientV2.configuration.host)
apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(
        client_id=clientID
        ,client_secret=clientSecret)

PureCloudPlatformClientV2.configuration.access_token = apiclient.access_token
logging.info("Recevied Access Token")


try:
    page_exists = True
    page = 1
    #truncate table
    GC.exe_sql_statment(db_connString= DbConnStr,sql_statement= 'Truncate table Staging_Dialer_Queues')
    # create an instance of the API class
    api_instance = PureCloudPlatformClientV2.RoutingApi()

    while (page_exists):

        api_response = api_instance.get_routing_queues(page_size=100, page_number = page)
        json_response = json.loads((api_response.to_json()))
        loadtoDB(region=region,DbConnStr=DbConnStr,table_name =table_name,data=json_response)         

        if json_response['page_count'] > 0 and (json_response['page_number'] < json_response['page_count']) :
            page = page + 1
            page_exists = False

        else:
            page_exists = False

except ApiException as e:
    logging.error("Exception when calling RoutingApi->get_routing_queues: %s\n" % e)

It works when i try to run the Region individually

Just an FYI. I am not looking to run multiple instance of the code on multiple azure function instances for multiple region. Looking to run multiple region on a same infrastructure instance without getting this issue

Hello,

Can you try with: api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient) ?
Also, I don't think that the following is necessary (access token is set on the apiClient inside the get_client_credentials_token method): # PureCloudPlatformClientV2.configuration.access_token = apiclient.access_token

Regards,

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