Api invocation in multiple regions of genesys cloud

Currently we have a Node JS application, where a method is implemented, responsible for completing client chats with the use of the API, postConversationDisconnect, from the node purecloud-platform-client-v2 library.

We use the same method for multi-region chat, that means that when a request arrives, we currently set the environment and the respective token, prior to executing the method, the problem is that the environments, apparently, are crossing or overwriting, when Requests come from different regions,

example: we set JP environment, but at the time of performing
When executing chat deletion, we see that the url used for deletion is from another region, attached method used.

disconnectChat = async (conversationId, tenant, logger) => {
     return new Promise( async (resolve, reject) =>{
         try{
             let client = platformClient.ApiClient.instance;
             client.setEnvironment(tenant.region);
 
             let auth = await client.loginClientCredentialsGrant(tenant.oauthRead.clientId, tenant.oauthRead.clientSecret);
 
             client.setAccessToken(auth.accessToken);
            
             let conversationsApi = new platformClient.ConversationsApi(client);
             // Get conversation threading window timeline for each messaging type
             await conversationsApi.postConversationDisconnect(conversationId)
             .then(() => {
                 logDebug("[connector][Open Messaging Engine][disconnectChat] Successfully");
                 resolve();
             })
             .catch((error) => {
                 throwerror;
             });
         }catch(error){
             logError("[connector][Open Messaging Engine][disconnectChat] Global : \n" + (typeof error == "object") ? JSON.stringify(error, null, 4) : error.toString(), null, { ...logger, event: "Pure Cloud Open Messaging Event" });
             reject(error);
         };
     });
};

You're using a singleton instance. From your description, it sounds like this function is being run multiple times concurrently. That will cause a race condition with each version of the function changing the region on the singleton client; it would also change the auth token. If you're building a multi-tennant application, you must isolate and maintain all instances per user/client so no objects are shared between instances of this function.

2 Likes

thx Tim, we are suspecting exactly this behavior.

Thanks for the quick feedback,