Facings issues in fetching Multiple users Subscription for Presence MS Graph API (For Microsoft Teams)

476 Views Asked by At

I am using MS Graph API for fetching the user's presences, now i am stuck at fetching multiple subscriptions. e.g. If i have 10 users in my teams tenant, i want to get subscriptions for their presences, so that when someone's presence changed i will get a subscription. The method i am using is working fine for single user. When i give single user id in resources, subscription works fine but for multiple users, am unable to use the filter clause which mentioned in many documents. Now now i need to add "/communications/presences?$filter=id in ({id},{id}…) (multiple users)" but am confused as it gives me invalid filter clause error if i add filter('') in it.

below code is working for single user

2

There are 2 best solutions below

2
HAMZA On

public getMSTeamsSubscriptionForPresence(ids) { try { let obj = { "changeType": "Updated", "userid": this.configService.getCustomerID, "expirationDateTime": "2021-12-22T10:45:39.2257768+00:00", "resource": "/communications/presences?$filter=id in (" + ids + ")", "notificationUrl": this.configService.apiUrl + "/teams", } return this.graphClient.api("/Subscriptions").post(obj); // } } catch (err) { console.log('error while getting subscription ', err); } }

where ids format will be 'id1','id2' etc.

14
Sayali-MSFT On

You check the filter documentation https://learn.microsoft.com/en-us/graph/query-parameters?context=graph%2Fapi%2Fbeta&view=graph-rest-beta#filter-parameter. You'll see that values actually need to have ' ' around them.

So if you change your request to the following it should work:

{ 
  "changeType": "updated", 
  "notificationUrl": "https://c3b9ebcxxxxx.ngrok.io/presence-notify/", 
  "resource": "/communications/presences?$filter=id in ('a3c710b2-33f8-4e7c-85b9-cbd88cdbxxxx','eab3e87b-473d-4d2d-9587-b7156b7exxxx')",
  "expirationDateTime": "2021-12-30T08:37:12Z", 
  "clientState": "secretClientState" 
}