10

I am aware of the beta Graph Presence API. However, this currently only allows retrieving Presence data. I would like to be able to change a Teams user's status availability using an api call. The most recent information that I could find is several years old: (Does Microsoft Teams have a way to update a user's status/presence?)

If the Teams API does not contain this functionality, can it still be done via the underlying UCWA API if that is still available for Teams? Or, more generally, is there some other way to have an external application update a Teams user's status availability?

Alternatively, is there a way to update the availability/status in Office 365 via an api call?

dda
  • 309
  • 1
  • 3
  • 15
  • Currently we don't have any API to update the presence, but you can fetch the user presence using [Graph API](https://learn.microsoft.com/en-us/graph/api/resources/presence?view=graph-rest-beta) – Nikitha-MSFT May 19 '20 at 10:19
  • @Nikitha-MSFT Wasn't someone in https://stackoverflow.com/questions/46608385/does-microsoft-teams-have-a-way-to-update-a-users-status-presence stating that it's doable via UCWA ? – sba923 Jun 18 '20 at 20:21
  • Following on what @Nikitha-MSFT was saying, there's also this issue as a reference - https://github.com/microsoftgraph/microsoft-graph-docs/issues/7010 - as well as this UserVoice item - https://microsoftteams.uservoice.com/forums/555103-public/suggestions/39651298-microsoft-graph-presence-api – jamiebarrow Feb 19 '21 at 11:37

3 Answers3

5

For anyone still interested, there's a new API available that allows to set user presence with application permission type.

https://learn.microsoft.com/en-us/graph/api/presence-setpresence?view=graph-rest-1.0&tabs=http

I've tested it and it seems to "mostly" work. I've observed 2 issues:

  1. user for whom the presence is set, does not see an update in their teams client (both desktop/web/mobile). Other people see the status is changed though.
  2. Setting Away/Away does not work - status is changed to Available/Available.

So although it's in 1.0 version, for me it's still more beta.

Łukasz Zwierko
  • 621
  • 7
  • 15
  • I've only ever worked with api-calls that work with delegated permissions. Am I right in assuming that I cannot use this api in a public app, since the permission type "application" basically requires me to get the consent of the user's teams tenant administrator? (and to install the app on a dedicated address for each tenant). That would seem a bigger issue than the two you've listed above. – mheim Dec 07 '21 at 15:19
  • 1
    Yes, my understanding is that application permissions are for service-to-service integrations and these are usually company-wide and need org admin approval. – Łukasz Zwierko Dec 07 '21 at 20:07
  • Btw I understand they've updated the API once again, seeing dnd is now available though by yet another API call – Łukasz Zwierko Dec 07 '21 at 20:08
4

if you login to teams web app and change availability status, you can see that the app is actually making PUT call to https://presence.teams.microsoft.com/v1/me/forceavailability/ with simple JSON body

{"availability":"Busy"}

It's unofficial probably, but maybe worth checking out?

Łukasz Zwierko
  • 621
  • 7
  • 15
  • The authorization token expires after ~1 hour, so it's not very useful. – gregers Nov 11 '21 at 09:57
  • That's kinda ancien approach to the issue. Checkout the new API https://learn.microsoft.com/en-us/graph/api/presence-setpresence?view=graph-rest-1.0&tabs=http It's still, in my opinion, not ready but maybe good enough for your requirements. – Łukasz Zwierko Nov 11 '21 at 13:55
2

Lukasz was correct, only thing is you need to provide bearer token as well in the header for authorization

curl --location --request PUT 'https://presence.teams.microsoft.com/v1/me/forceavailability/' \--header 'Authorization: Bearer your_token_here --header 'Content-Type: application/json' \--data-raw '{    "availability": "Busy"}'
user2739602
  • 301
  • 5
  • 4
  • But the teams web app token for this service is only valid for one hour. Hardly worth the effort to extract it from the browser to automate your status when your system is bound to break after one hour. Or have you found a method to retrieve the required token yourself? – mheim May 26 '21 at 16:14
  • I got this working and implemented a chrome extension and bash script that work together to keep the status green unless the screensaver kicks in. See getAuthToken() here: https://github.com/poleguy/teams_green/blob/main/src/js/script.js – poleguy Jan 04 '23 at 16:07
  • 1
    @mheim I use the Az CLI to get a bearer token - this is much longer lived (can even be obtained dynamically depending on authentication methods), to pass into this PUT call – AutomationNation Mar 07 '23 at 03:41