Legacy Dev Forum Posts

 View Only

Sign Up

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

  • 1.  GET /api/v2/conversations/chats/{conversationId} return 401

    Posted 06-05-2025 18:03

    Indra_Gheorghe | 2021-08-23 13:25:37 UTC | #1

    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.GENESYSCLIENTID, process.env.GENESYSCLIENTSECRET);

    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


    anon11147534 | 2021-08-24 11:43:32 UTC | #2

    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.


    Indra_Gheorghe | 2021-08-25 07:11:12 UTC | #3

    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


    Indra_Gheorghe | 2021-08-25 09:29:25 UTC | #4

    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


    anon11147534 | 2021-08-26 10:22:49 UTC | #5

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


    system | 2021-09-26 10:22:55 UTC | #6

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


    This post was migrated from the old Developer Forum.

    ref: 11809