Send an activity feed notification in the scope of a team. For more details about sending notifications and the requirements for doing so, see
sending Teams activity notifications.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Note: The entity URL must be same or child resource of the team in the URL. Additionally, the Teams app must be installed in the team.
Response
If successful, this action returns a 204 No Content response code.
Examples
Example 1: Notify a user about pending finance approval requests
This example shows how you can send an activity feed notification for a team. This example notifies the team owner about pending finance approval requests.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Teams.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/{teamId}",
},
ActivityType = "pendingFinanceApprovalRequests",
PreviewText = new ItemBody
{
Content = "Internal spending team has a pending finance approval requests",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "569363e2-4e49-4661-87f2-16f245c5d66a"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "pendingRequestCount",
Value = "5",
},
},
};
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/{teamId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('pendingFinanceApprovalRequests');
$previewText = new ItemBody();
$previewText->setContent('Internal spending team has a pending finance approval requests');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => '569363e2-4e49-4661-87f2-16f245c5d66a',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('pendingRequestCount');
$templateParametersKeyValuePair1->setValue('5');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody);
Similar to the previous example, this example uses entityUrl for the topic. However, this example links to a tab in a channel. The tab hosts a page showing the user the status of their hotel reservation. Selecting the notification will take the user to the tab, where they can check their reservation.
POST https://graph.microsoft.com/v1.0/teams/{teamId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/tabs/{tabId}"
},
"activityType": "reservationUpdated",
"previewText": {
"content": "You have moved up the queue"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "569363e2-4e49-4661-87f2-16f245c5d66a"
},
"templateParameters": [
{
"name": "reservationId",
"value": "TREEE433"
},
{
"name": "currentSlot",
"value": "23"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Teams.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/tabs/{tabId}",
},
ActivityType = "reservationUpdated",
PreviewText = new ItemBody
{
Content = "You have moved up the queue",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "569363e2-4e49-4661-87f2-16f245c5d66a"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "reservationId",
Value = "TREEE433",
},
new KeyValuePair
{
Name = "currentSlot",
Value = "23",
},
},
};
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/tabs/{tabId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('reservationUpdated');
$previewText = new ItemBody();
$previewText->setContent('You have moved up the queue');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => '569363e2-4e49-4661-87f2-16f245c5d66a',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('reservationId');
$templateParametersKeyValuePair1->setValue('TREEE433');
$templateParametersArray []= $templateParametersKeyValuePair1;
$templateParametersKeyValuePair2 = new KeyValuePair();
$templateParametersKeyValuePair2->setName('currentSlot');
$templateParametersKeyValuePair2->setValue('23');
$templateParametersArray []= $templateParametersKeyValuePair2;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody);
Example 3: Notify a user about a channel tab using user principal name
Similar to the previous example, this example uses entityUrl for the topic. However, this example links to a tab in a channel. The tab hosts a page showing the user the status of their hotel reservation. Selecting the notification will take the user to the tab, where they can check their reservation.
POST https://graph.microsoft.com/v1.0/teams/{teamId}/sendActivityNotification
Content-Type: application/json
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/tabs/{tabId}"
},
"activityType": "reservationUpdated",
"previewText": {
"content": "You have moved up the queue"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "jacob@contoso.com"
},
"templateParameters": [
{
"name": "reservationId",
"value": "TREEE433"
},
{
"name": "currentSlot",
"value": "23"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Teams.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/tabs/{tabId}",
},
ActivityType = "reservationUpdated",
PreviewText = new ItemBody
{
Content = "You have moved up the queue",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "jacob@contoso.com"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "reservationId",
Value = "TREEE433",
},
new KeyValuePair
{
Name = "currentSlot",
Value = "23",
},
},
};
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/tabs/{tabId}');
$requestBody->setTopic($topic);
$requestBody->setActivityType('reservationUpdated');
$previewText = new ItemBody();
$previewText->setContent('You have moved up the queue');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => 'jacob@contoso.com',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('reservationId');
$templateParametersKeyValuePair1->setValue('TREEE433');
$templateParametersArray []= $templateParametersKeyValuePair1;
$templateParametersKeyValuePair2 = new KeyValuePair();
$templateParametersKeyValuePair2->setName('currentSlot');
$templateParametersKeyValuePair2->setValue('23');
$templateParametersArray []= $templateParametersKeyValuePair2;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody);
Example 4: Notify a user about an event using custom topic
As seen in the previous examples, you can link to different aspects of the team. However, if you want to link to an aspect that is not part of the team or is not represented by Microsoft Graph, or you want to customize the name, you can set the source of the topic to text and pass in a custom value for it. webUrl is required when setting topic source to text.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Teams.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.Text,
Value = "Deployment Approvals Channel",
WebUrl = "https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000",
},
ActivityType = "deploymentApprovalRequired",
PreviewText = new ItemBody
{
Content = "New deployment requires your approval",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.aadUserNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"userId" , "569363e2-4e49-4661-87f2-16f245c5d66a"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "deploymentId",
Value = "6788662",
},
},
};
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('text'));
$topic->setValue('Deployment Approvals Channel');
$topic->setWebUrl('https://teams.microsoft.com/l/message/19:448cfd2ac2a7490a9084a9ed14cttr78c@thread.skype/1605223780000?tenantId=c8b1bf45-3834-4ecf-971a-b4c755ee677d&groupId=d4c2a937-f097-435a-bc91-5c1683ca7245&parentMessageId=1605223771864&teamName=Approvals&channelName=Azure%20DevOps&createdTime=1605223780000');
$requestBody->setTopic($topic);
$requestBody->setActivityType('deploymentApprovalRequired');
$previewText = new ItemBody();
$previewText->setContent('New deployment requires your approval');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.aadUserNotificationRecipient');
$additionalData = [
'userId' => '569363e2-4e49-4661-87f2-16f245c5d66a',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('deploymentId');
$templateParametersKeyValuePair1->setValue('6788662');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody);
Example 5: Notify the team members about pending finance approval requests
The following example shows how you can send an activity feed notification to all team members. This example is similar to previous examples. However, in this case, the recipient is a teamMembersNotificationRecipient. Note that the teamId specified in the recipient must match the teamId specified in the request URL.
Note: The ability to send notifications to all team members is limited to teams with 10,000 members or less. If the team exceeds 10,000 members, none of the team members will receive a notification.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Teams.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/e8bece96-d393-4b9b-b8da-69cedef1a7e7",
},
ActivityType = "pendingFinanceApprovalRequests",
PreviewText = new ItemBody
{
Content = "Internal spending team has a pending finance approval requests",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.teamMembersNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"teamId" , "e8bece96-d393-4b9b-b8da-69cedef1a7e7"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "pendingRequestCount",
Value = "5",
},
},
};
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/e8bece96-d393-4b9b-b8da-69cedef1a7e7');
$requestBody->setTopic($topic);
$requestBody->setActivityType('pendingFinanceApprovalRequests');
$previewText = new ItemBody();
$previewText->setContent('Internal spending team has a pending finance approval requests');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.teamMembersNotificationRecipient');
$additionalData = [
'teamId' => 'e8bece96-d393-4b9b-b8da-69cedef1a7e7',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('pendingRequestCount');
$templateParametersKeyValuePair1->setValue('5');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody);
Example 6: Notify the channel members about pending finance approval requests
The following example shows how you can send an activity feed notification to all channel members. This example is similar to the previous example. However, in this case, the recipient is a channelMembersNotificationRecipient. Note that the teamId specified in the recipient must match the teamId specified in the request URL.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Teams.Item.SendActivityNotification.SendActivityNotificationPostRequestBody
{
Topic = new TeamworkActivityTopic
{
Source = TeamworkActivityTopicSource.EntityUrl,
Value = "https://graph.microsoft.com/v1.0/teams/e8bece96-d393-4b9b-b8da-69cedef1a7e7",
},
ActivityType = "pendingFinanceApprovalRequests",
PreviewText = new ItemBody
{
Content = "Internal spending team has a pending finance approval requests",
},
Recipient = new TeamworkNotificationRecipient
{
OdataType = "microsoft.graph.channelMembersNotificationRecipient",
AdditionalData = new Dictionary<string, object>
{
{
"teamId" , "e8bece96-d393-4b9b-b8da-69cedef1a7e7"
},
{
"channelId" , "19:3d61a2309f094f4a9310b20f1db37520@thread.tacv2"
},
},
},
TemplateParameters = new List<KeyValuePair>
{
new KeyValuePair
{
Name = "pendingRequestCount",
Value = "5",
},
},
};
await graphClient.Teams["{team-id}"].SendActivityNotification.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new SendActivityNotificationPostRequestBody();
$topic = new TeamworkActivityTopic();
$topic->setSource(new TeamworkActivityTopicSource('entityurl'));
$topic->setValue('https://graph.microsoft.com/v1.0/teams/e8bece96-d393-4b9b-b8da-69cedef1a7e7');
$requestBody->setTopic($topic);
$requestBody->setActivityType('pendingFinanceApprovalRequests');
$previewText = new ItemBody();
$previewText->setContent('Internal spending team has a pending finance approval requests');
$requestBody->setPreviewText($previewText);
$recipient = new TeamworkNotificationRecipient();
$recipient->set@odatatype('microsoft.graph.channelMembersNotificationRecipient');
$additionalData = [
'teamId' => 'e8bece96-d393-4b9b-b8da-69cedef1a7e7',
'channelId' => '19:3d61a2309f094f4a9310b20f1db37520@thread.tacv2',
];
$recipient->setAdditionalData($additionalData);
$requestBody->setRecipient($recipient);
$templateParametersKeyValuePair1 = new KeyValuePair();
$templateParametersKeyValuePair1->setName('pendingRequestCount');
$templateParametersKeyValuePair1->setValue('5');
$templateParametersArray []= $templateParametersKeyValuePair1;
$requestBody->setTemplateParameters($templateParametersArray);
$graphServiceClient->teams()->byTeamId('team-id')->sendActivityNotification()->post($requestBody);