How do you subscribe to push notifications in microsoft graph? - https

I have been trying to figure out how to use the beta notifications resource to send push notifications to users in Teams, but I cannot get past step 1.
User signs in to your application, which creates a subscription with the Microsoft Graph notification service.
I am not using a language with Microsoft library support so I cannot use their SDKs. Instead, I am manually sending http requests. I have tried many, but I can't even nail down what the "resource" is supposed to be in the subscription type. Here are some of the things I have tried and the results:
Sending this message:
{
"changeType": "created",
"notificationUrl": "https://(...)/notifications",
"resource": "me/notifications",
"expirationDateTime": "2020-11-04T18:23:45.9356913Z"
}
Results in:
{
"error": {
"code": "InvalidRequest",
"message": "Subscription for resource 'me/notifications' is not supported.",
"innerError": {
"date": "2020-11-04T17:12:24",
"request-id": "66172d3c-298d-47d4-babb-52d96ef42179",
"client-request-id": "1c20849c-fcda-0b07-56e3-5bed08bb28e4"
}
}
}
The above message also correctly calls my server's /notifications route with this param:
Validation: Testing client application reachability for subscription Request-Id: 2f3cc3b8-b2c2-5922-451c-433add43bc74
Sending this one:
{
"changeType": "created",
"notificationUrl": "https://(...)/notifications",
"resource": "notification",
"expirationDateTime": "2020-11-04T18:23:45.9356913Z"
}
Results in:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'notification'.",
"innerError": {
"date": "2020-11-04T17:21:15",
"request-id": "d894c93b-9dac-4051-a3af-cb6039f1394b",
"client-request-id": "84d18ec7-2c67-8240-b576-03641b3b5a59"
}
}
}
I have also tried "notifications", "users/me/notifications", and a few others to no avail. What's the deal, Microsoft? This resource isn't even listed under the possible subscription types in the beta docs, so is it supported or not?

At this point I'm pretty sure this functionality just doesn't work/exist.

Related

Microsoft graph API - unable to use $filter operation in "toRecipients" array

Hello guys hope ur doing good,
I want to filter out the graph api response based on the "toRecipient" which is a array, hence I used lambda expression, but it gives error.
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes.",
"innerError": {
"date": "2021-09-22T06:04:17",
"request-id": "c6077cd4-dbec-4671-9c11-10e547917d29",
"client-request-id": "66dfbc92-2482-11f3-86f9-22652a4e4e00"
}
}
My actual response is
"toRecipients": [
{
"emailAddress": {
"name": "abc",
"address": "abc#abc.com"
}
}
],
I had used this operation to filter out
https://graph.microsoft.com/v1.0/me/mailFolders/sentItems/messages?&$top=1000&$search="abc#abc.com"
Graph API calls underlaying Office 365 API.
According to the documentation, property ToRecipients is not filterable.

InvalidAudienceForResource exception with Exchange.Callback.V2 token in Outlook for iOS

I have an Outlook add-in with ReadWriteMailbox permissions that calls Office.context.mailbox.getCallbackTokenAsync({isRest: true}) to get what is generally a valid auth token:
{
"oid": "oid",
"puid": "puid",
"smtp": "xxx",
"upn": "xxx",
"clientappid": "3382ce5c-ed22-4195-aeca-c5b67384706f",
"ver": "Exchange.Callback.V2",
"appid": "00000002-0000-0ff1-ce00-000000000000",
"deploymentid": "https://outlook.office365.com/",
"tid": "tid",
"acr": "1",
"appidacr": "0",
"scp": "Mail.ReadWrite Mail.Send Calendars.ReadWrite Contacts.ReadWrite",
"nbf": 1588259750,
"exp": 1588260650,
"iss": "https://outlook.office365.com/",
"aud": "a_vanity_url",
"happ": "API"
}
In Outlook for iOS, I am now seeing this exception in a handful of environments:
{
"readyState": 4,
"responseText": "omitted_for_redundancy",
"responseJSON": {
"error": {
"code": "InvalidAudienceForResource",
"message": "The audience claim value is invalid for current resource.
Audience claim is 'a_vanity_url',
request url is 'https://outlook.office365.com/api/v2.0/me/messages/a_message_id'
and resource type is 'Exchange'.",
"innerError": {
"requestId": "requestId",
"date": "2020-04-30T15:15:51"
}
}
},
"status": 401,
"statusText": "Unauthorized"
}
The common theme seems to be whenever an MDM/MAM is configured (usually Intune), and it's happening across all managed devices on the tenant, and continues to fail until a device is unregistered and its Outlook accounts are removed and re-added.
Is there something I can do differently when I request an auth token to prevent this failure? Or is there a device management setting that Outlook for iOS requires to run add-ins?
Thank you for reporting and it seems like it is not an addin issue. Can you please raise a support case with Intune by going to Link, navigate to "Troubleshooting + Support". The corresponding team will address the issue.
The workaround here is just to use the vanity domain returned in the JWT's audience claim as the API URL base instead of the value returned by Office.context.mailbox.restUrl.

Problem with create team with Microsoft Graph Api

I have a problem with creating teams using the Microsoft Graph Api. I can get/create groups but when I try to get/create teams I get an error. I'm using postman and the group has owners and members, just as the documentation of MS, also has the permissitions it asks for groups. If somebody can help me, cause I look everywhere for a same error but no found it.
PUT https://graph.microsoft.com/v1.0/groups/{id}/team
Headers: Authorization: bearer token and content-type: json
Body is
{
"memberSettings": {
"allowCreateUpdateChannels": true
},
"messagingSettings": {
"allowUserEditMessages": true,
"allowUserDeleteMessages": true
},
"funSettings": {
"allowGiphy": true,
"giphyContentRating": "strict"
}
}
I always get the same error
{
"error": {
"code": "BadGateway",
"message": "Failed to execute backend request.",
"innerError": {
"request-id": "45eeba8a-9d35-45e8-b42e-c60da7a47dde",
"date": "2020-01-23T21:55:44"
}
}
}
According to the Graph API docs for this, you're not calling the correct endpoint to create a new Team. It should be
POST https://graph.microsoft.com/beta/teams
and a payload similar to
Content-Type: application/json
{
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates('standard')",
"displayName": "My Sample Team",
"description": "My Sample Team’s Description",
"owners#odata.bind": [
"https://graph.microsoft.com/beta/users('userId')"
]
}
Note that it's slightly different, as per the docs, whether you're using delegated versus application permissons.

office 365 outlook Graph api custom email message header

In order to organize emails into single thread GMail requires custom headers to be set within incoming message. Is there any way to set custom headers when sending Office O365 Outlook message through the Graph API? The documentation states about custom headers option through the InternetMessageHeaders property, however it is required to start header name with 'x-' appendix, which makes it not usable. For example, this message is supposed to set some custom headers, however, due to the 'x-' prefix limitation, this can't be used for organizing GMail messages:
POST https://graph.microsoft.com/v1.0/me/sendMail
Content-type: application/json
{
"message": {
"subject": "9/9/2018: concert",
"body": {
"contentType": "HTML",
"content": "The group represents Nevada."
},
"toRecipients": [
{
"emailAddress": {
"address": "AlexW#contoso.OnMicrosoft.com"
}
}
],
"internetMessageHeaders":[
{
"name":"x-custom-header-group-name",
"value":"Nevada"
},
{
"name":"x-custom-header-group-id",
"value":"NV001"
}
]
}
}
https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http
Is there any way to specify custom headers: 'References', 'In-Reply-To' without the prefix 'x-'?
https://gsuiteupdates.googleblog.com/2019/03/threading-changes-in-gmail-conversation-view.html
When trying to set custom email headers without 'x-' prefix, the Graph API returns following error message:
{
"error": {
"code": "InvalidInternetMessageHeader",
"message": "The internet message header name 'References' should start with 'x-' or 'X-'.",
"innerError": {
"request-id": "441e21b7-d4ca-47d3-957a-a72bcc854a67",
"date": "2019-12-10T14:28:35"
}
}
}
One workaround might be to use the Extended properties to set those values eg the In-Reply-to https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtaginreplytoid-canonical-property should look something like
"singleValueExtendedProperties": [
{
"id":"String 0x1042",
"value":"342342343234#domain.com"
}
]

Can't subscribe a GMB business to pub/sub push notifications

I spent several hours trying to solve this stuff.
I need to subscribe a gmb business to pub/sub push notifications. I was able to send/receive messages via gcloud console. Successfully created a topic and a subscription. The problem is that i need to subscribe gmb accounts , but I'm getting this error:
(had to edit this question, the code is better than images)
The request:
PUT https://mybusiness.googleapis.com/v4/accounts/102834134483270918765/notifications
{
"topicName": "projects/probable-pager-194417/topics/fetchReviews",
"notificationTypes": [
"NEW_REVIEW", "UPDATED_REVIEW", "GOOGLE_UPDATE"
]
}
The Response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
"errorDetails": [
{
"code": 3,
"message": "Invalid topic name provided for subscription. Ensure that the topic exists and is shared with the GMB API service account.",
"value": "projects/probable-pager-194417/topics/fetchReviews"
}
]
}
]
}
}
Finally i found the solution. You need to give Pub/Sub Publisher permission in your topic to this account: 'mybusiness-api-pubsub#system.gserviceaccount.com. Have no idea why.
**Exactly that string

Resources