Notification service subscribe

Hi everyone,

I have OAuth client application and I want to subscribe it to notification topic and get data from WebSocket.
v2.users.{userId}.workforcemanagement.historicaladherencequery

But I cant do it, because my OAuth client application has not userId.

Could someone please help me?
What should I do to get this data?

Thank and best regards,
Alex

Hello, here's a thread about this: Problems getting historical adherence

TLDR; use the requesting user's ID when using a user-based grant and use your oauth client ID when using client credentials.

2 Likes

Thanks for quick answer.

I tried it before creating thread, but, unfortunately, it didn`t work.
Get 404 error.

Can you be more specific about exactly what you tried? Can you share details of the request and response?

Firstly, I checked that I have necessary topic in list of topics
https://api.mypurecloud.com/api/v2/notifications/availabletopics

Secondly, I created WebSocket channel via POST
https://{API URL by region}/api/v2/notifications/channels
And got connectUri and id from that

Thirdly, I POST
/api/v2/notifications/channels/{channelId}/subscriptions
Where channelId == id of channel from previous step
And put in json body
{"id":"v2.users.{client_id}.workforcemanagement.historicaladherencequery"}
with

With client id from my OAuth Client Grant Credentials

And I got 404 error with "The request could not be understood by the server due to malformed syntax"

From the documentation on the subscription route:

POST /api/v2/notifications/channels/{channelId}/subscriptions

The request body is required to be an array of objects with IDs, like so:

[
  {
    "id": ""
  }
]

I personally find the request body schema easier to follow if you click the "Json" tab rather than looking at the "schema" tab, I hope this helps

Oh my god, it finally subscribed. I thought I didn`t need to use [ ] for one value.

Remains to understand why I do not receive messages in WebSocket messages after to api/v2/workforcemanagement/managementunits/{id}/historicaladherencequery
except WSMessage(type=<WSMsgType.TEXT: 1>, data='{"topicName": "channel.metadata", "eventBody": {"message": "WebSocket Heartbeat"}}', extra='')

Can you provide a correlationId for one of the requests to
/api/v2/workforcemanagement/managementunits/{id}/historicaladherencequery?

Finally, I did it with you help, guys

Thanks a lot!

The root of issue was that every access token has own channels and topics, so i did it in different clients and hoped message from WS.

It's very nice that you helped me so quickly, you are cool

@tim.smith
@brian.trezise

2 Likes

Happy to be of assistance and I'm glad you were able to get it working!

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