Not able to send messages via Guest Chat Api

Hi,

I trying to follow the documentations related to send/receive messages via Guest Chat API described on Guest Chat API and I got stucked when I try to send message from guest to agent.

I was able to get a valid access token via /login.mypurecloud.com/oauth/token.
Create a ACD conversation with /api/v2/webchat/guest/conversations.
Connect via webscoket to the uri provided on creation (eventStreamUri).
Get the messages sent by the agent from PureCloud Platform and its memberId.

But I was NOT able to send messages from guest to agent via /api/v2/webchat/guest/conversations/{conversationId}/members/{memberId}/messages. Instead I'm getting a "You are not authorized to perform the requested . For memberId, I'm using the one specified on sender message received from agent.

I'm using an App created with Grant Type Client Credentials from where I get Client Id and CLient Secret to get the accessToken which I use for the rest of operations. It app also is set with Roles WebChat Development.

Any idea.
Thanks in advance.

It sounds like you're doing guest operations - and when doing the guest operations the part you mention about "Grant Type Client Credentials" is likely your mistake. From the guest's side, you don't want to do anything with grants or client secrets or any of that - all that stuff is for the agent's side only.

To do authorization right from the web guest's side it's very simple: when you create a chat it returns a JWT in the response body. From then on, just use that JWT in every subsequent request as an HTTP header of "Authorization": "bearer {your JWT}" and that's it. You don't have to (and in fact can't) do anything with grants or secrets or anything else.

Hope this helps!
Dan

1 Like

Great! I've just check and It worked.

Note that memberId on send message endpoint is guest memberId and not agent memberId. It was also another mistake.

Thanks!

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