GET /api/v2/conversations/chats/{conversationId} return 401

Hi,

I need to get the conversation details using this api endpoint /api/v2/conversations/chats/{conversationId}
however i get a 401 using the SDK

What i did:
1.

let client = purecloudPlatformClient.ApiClient.instance;
client.config.setConfigPath('......./config/genesys.json');
loginResponse = await client.loginClientCredentialsGrant(process.env.GENESYS_CLIENT_ID, process.env.GENESYS_CLIENT_SECRET);
redis.set(${id}_loginToken, JSON.stringify(loginResponse));

This works, because i then use this to start a webchat conversation and there is no error there

  1. to get the conversation
let loginResponse = await this.redisWrapper.get(`${id}_loginToken`);
client.setAccessToken(loginResponse.accessToken);

again this returns the proper token and then we set it

const apiInstance = new purecloudPlatformClient.ConversationsApi();
return apiInstance.getConversation(conversationId);

the last bit where i try to do get conversation resturn an error. The weird thing is that sometimes (like 2%) of the time it works.

What are we doing wrong? Thank you

Hi,

I'm not sure why you're logging in again in step 2. The access token will have been set in the SDK from loginClientCredentialsGrant.
Although this shouldn't cause an issue if this token returned from redisWrapper.get(${id}_loginToken); is valid.

We log in again in case the token expired, but tbh we tried without and actually removed the second login since posting the question and it makes no difference. The only thing that made a difference was restarting the app. After restarting the app getConversation works using the same token so now it's even more confusing

Issue found: we are using both conversationapi and webchatapi and their authentication methods are not compatible. Fixed by spliting them. I wish this was made clear in the docs

1 Like

Apologies for that. I'll get the SDK docs updated to reflect that.

1 Like

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