简体   繁体   中英

How can we trigger an event from MS Teams (and call an external app) when a new team is created in MS Teams?

When any user creates a new team in MS Teams we want to propagate this information to our custom application and perform some actions. Is there any way to trigger this event?

You can use Change notifications to receive webhooks to your own api endpoint.

To receive a webhook for a new event , you have to create a new subscription (See Create subscription ) and use /users/{id}/events as resource . Change {id} to the Id of the user you want to subscribe to.

Because you only want to receive new events, set ChangeType to created . You can also use updated or deleted and to chain them, use , .


Example request to create a new subscription

POST https://graph.microsoft.com/beta/subscriptions
Content-type: application/json
{
   "changeType": "created",
   "notificationUrl": "https://yourbackend.tld/api/new-event",
   "resource": "/users/{id}/events",
   "expirationDateTime":"2022-05-21T11:21:32.5261217Z",
}

expirationDateTime

Please be aware that the expirationDateTime has a maximum value. See Maximum length of subscription per resource type . The maximum value for events is 4230 minutes.

You can renew a subscription by extending its expiry time, see Update subscription .


Immutable identifiers for Outlook resources

I would also recommend to use the header Prefer: IdType="ImmutableId" to ensure that the Id of an event doesn't change over time. Read more about this here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM