Microsoft Graph WebHook: Subscription validationtoken blank? - microsoft-graph-api

I'm trying to setup a MS Graph webhook subscription for messages, but it appears that Graph is sending a blank validationToken. I'm connecting to https://graph.microsoft.com/beta/subscriptions
My API endpoint works in Postman and successfully returns a plaintext response with only the validationtoken, but when I call MS Graph, I get the following error "Subscription validation request failed. Response must exactly match validationToken query parameter". I've also tried both validationtoken and validationToken as the parameter to look for.
Full error message
"{\r\n \"error\": {\r\n \"code\": \"InvalidRequest\",\r\n \"message\": \"Subscription validation request failed. Response must exactly match validationToken query parameter.\",\r\n \"innerError\": {\r\n \"request-id\": \"f1546835-606d-4bd8-ab3c-dfb2c75285aa\",\r\n \"date\": \"2018-08-10T03:45:56\"\r\n }\r\n }\r\n}"

To create a subscription you need to expose a notification URL with https (You can look at Graph documentation at https://developer.microsoft.com/en-us/graph/docs/concepts/webhooks).
When you send your create subscription request, the first post message your notification URL will receive is a message with a validation token. You have to send this validation token back. Now you should receive notifications on your specified notification URL. Looking at this failure, it looks like the notification URL is not sending the validation token back.
The response should not vary between Postman and MSGraph. If you are still seeing issues, please share your notification url and we will try to get a repro.

Related

how to prevent message creation api to resend complete message

I use graph api to create a message with attachment(s).
All runs fine but the server send back the complete message in response, including the attachments.
Is there a way to only get the message id in the response ?
I try with :
string webApiUrl = $"{_apiUrl}v1.0/users/{senderId}/messages?$select=id"
but I still get the whole message with 98ko of attachment.
You can do it using the prefer:return=minimal header in the request which will mean you will just get a 204 response. However the id of the item that was created will be returned in the location header (the response should really have the OData-EntityId if they are following the oData spec to the letter, also I'm not sure why it return the Outlook v2 location rather then the graph but the message Id is the same between them)

Runtime Error when sending a search request to outlook for a keyword that does not exist in the mailbox

When searching for a keyword ("Test email"), using Outlook API, and the keyword exist in my mailbox, I retrived a result within a second. However, if the keyword ("blablabla") does not exist in the mailbox I do not get a reply. Almost after 2 minutes I get a runtime error.
http get on: https://outlook.office365.com:443/api/v2.0/users/user#sub.onmicrosoft.com/messages?$search=blablablablabla&$top=100&$select=Sender,ToRecipients,CcRecipients,Weblink,Subject,ReceivedDateTime,BodyPreview
http headers:
Authorization: bearer theToken
x-AnchorMailbox: theEmailAddress
I expected to get an HTTP Response that says something like "Could not find any result"
Instead I get no reply upto two minutes and than a runtime error with that yellow background that instructs to turn on
<customError mode="Off" />
Though the http staus code is 200.
I think as an API consumer I should not get such replies.

Request/reply with rest

I'm unable to implement request/reply pattern using rest protocol with solace.
I'm correctly receiving a request and I can see some headers like "solace-correlation-id" and "solace-message-id".
What I'm expecting is to return an http response with the body as message reply but I always get in my application:
org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: xxxxx-1549904557890-0-26 not received on destination: #P2P/QTMP/v:cfdce68771f5/c9c4ba4a-a427-438a-9b7a-1f069608d13a.
Unfortunately the solace documentation only covers pub/sub pattern for rest but not the request/reply one.
There could be a few different things going on here.
Firstly try adding the log component between the "from" and "to" endpoints and again after the "to" endpoint as this will show you the headers of the reply, for example, using the Java DSL syntax:
from("{{fromSource}}" )
.to("log:all?level=INFO&showAll=true&multiline=true")
.to("{{toDest}}" )
.to("log:all?level=INFO&showAll=true&multiline=true")
;
I suspect the correlation id is not getting passed back. In my example I have a a NodeJS service so I set the following response header:
res.setHeader('solace-correlation-id', req.get('solace-correlation-id'));
With the additional logging, you should be able to see what is going wrong.
You are most likely missing the message ID or coorelation ID in your reply message.
https://docs.solace.com/RESTMessagingPrtl/Solace-REST-Message-Encoding.htm#2.2.6.1
When the Solace message broker receives a possible reply message routed to the HTTP client, it verifies that the reply message's message ID or correlation ID match those of the request message.
Specifically,
- the reply's message ID must match the request's message ID the
- reply's correlation ID must match the request's message ID, or the
- reply's correlation ID must match the request's correlation ID.
If any of those matches occur, the Solace message broker sends the reply message as an HTTP response to the HTTP client.
HTTP requires that there be exactly one HTTP response for each HTTP request, so each matching message ID or correlation ID can be used only in a single request-reply message exchange pattern.
If the reply message does not have a matching message ID or correlation ID as above, or if the reply message's matching message ID or correlation ID has already been consumed by an earlier reply message, the reply message is discarded.

Not able to create calendar events webhook

I am trying to create a subscription for calendar events. But I am getting 400 error with message containing:
"code": "InvalidRequest",
"message": "Subscription validation request failed. Must respond with 200 OK to this request."
As per webhook validation doc my server should have received call on notificationUrl passed in subscription post body, which is not happening for some reason. I can confirm this same POST notificationUrl could be accessed by me and it accepts validationToken as query param.
Can someone please help here.
your service must respond to this validation request by returning the value of the validationtoken query string parameter as a plain-text response.
something like
[HttpPost]
public async Task<ActionResult> Listen()
{
if (Request.QueryString["validationToken"] != null)
{
var token = Request.QueryString["validationToken"];
return Content(token, "plain/text");
}
}
Managed to resolve after checking access logs. Validationtoken request was getting blocked with 415 error because my api was only accepting json. Ensured that it can also accept "text/plain" and it is now working.

How do I get an HTML response from a Zapier catch hook

I have a zap that gets invoked by a URL sent to a user in an email. The user clicks on the url, that invokes the zap. The zap then does some work removing items from a google calendar. All that works perfectly. However, the user gets a JSON response like:
{ "status": "success", "attempt": "58f76ead-ffa8-4807-b4a4-9cb31537ace0", "id": "556d2bd7-e413-4fe0-9602-af4bfbba1f48", "request_id": "zjd5zKTwCgtdDYS0" }
I would prefer that the user got an HTML response. Is this a javascript/python coding issue? Is there some unusually named zapier function that does this already?
It's not possible to define the response content returned by requests made to a Zapier webhook URL. The response will always be a JSON response with basic status/meta data.
To get what you're looking for, you'd need to link your users to a webpage that will in turn make an HTTP request to Zapier when they visit.

Resources