Creating a Subscription in MS Graph error

Trying to create webhook subscription in MS Graph for mail messages.
Posting the request in FM, getting a 405 Method not allowed error.
Posting same request in Postman, getting “Subscription validation request failed. Notification endpoint must respond with 200 OK to validation request.”
API Key configured.
Webhook registered.
FM Insert from URL as follows:
URL: https://graph.microsoft.com/v1.0/subscriptions
cURL: -X Post -H “Authorization: Bearer {{token}}” -H “Content-type: application/json” -D $header -d @$data
$data: {
“changeType” : “created”,
“clientState” : “secretClientState”,
“expirationDateTime” : “2024-06-24T13:52:43.0000000Z”,
“notificationUrl” : “https://{{domain}}.com/otto/receiver/Webhook Receiver.fmp12/libdocs?apiKey={{key}}”,
“resource” : “/users/{{id}}/messages”
}

Please advise how to correct this…

Thanks in advance,

Hey Tom,

OttoFMS Webhooks do not natively handle validation requests, but you can build it into the reciever script with Webhook Responses. You should be able to accept the incoming validation requests and set up the response to send a 200 yourself.

The Microsoft docs have a walkthrough that should let you know how the incoming request will be structured and how you will need to set up the response.

Let us know if that works for you!

-Kyle

Thanks for your response.

I’ve found the criteria that MS Graph requires, listed below:

The client must respond with the following characteristics within 10 seconds of step 1:

** A status code of HTTP 200 OK.*
** A content type of text/plain.*
** A body that includes the URL decoded plain text validation token.*

No problem with the first 2, but is there a way to process the 3rd requirement?

Hey Tom,

The token should be passed through as part of the script params from OttoFMS. I would try using it the way it is passed in first as I am not sure if it will be encoded still at that point. If it is still encoded you will need to decode it. FileMaker does not have a built in function to decode URL-encoded strings (as far as I know) you’ll need to use a custom function to decode it.

You’ll have to do some debugging of the token that you’re getting from the request and see what value you’re getting.

-Kyle

(Not sure you received the email response)

The validation token is included as part of the URL:

Content-Type: text/plain; charset=utf-8
POST https://{notificationUrl}?validationToken={opaqueTokenCreatedByMicrosoftGraph}

I understand about decoding. How can I capture the validation token is its not in the payload?

Thanks,

OttoFMS takes the URL query parameters and includes them in the payload. It should be passed through to the script as part of its arguments.

-Kyle

I have successfully POSTed a Create Subscription request that creates a record in OttoReceiver, but am now faced with the validation problem.

As you can see in the screenshot, the payload is empty. I need the validation token that is included in the URL parameters.

Any advice?

Hi Tom.

The query parameters are passed to the OttoReceiver Script as the Script Parameter. You can modify the OttoReceiver script to use Get(ScriptParameter) to get those values and either pass them into the payload or Put them in a different field which you can create for this purpose, or just pass them to your script.

Let us know if we have given you enough information to get this in place.

Thanks

Todd