Lazloo Xp
Lazloo Xp

Reputation: 988

Creating Subscription for Microsoft Graph API: Subscription validation request failed

I try to create a Subscription for Microsoft Graph API. However, I get the error

Subscription validation request failed. Response must exactly match validationToken query parameter.

The Validation Request looks as follows :

POST /?validationToken=Validation%3a+Testing+client+application+reachability+for+subscription+Request-Id%3a+c69b04df-f3d3-411c-8ceb-7f1ad8b7a927 HTTP/1.1

Using FastApi, the API where validation request is sent to look like

from fastapi import FastAPI

app = FastAPI()

@app.post("/")
def read_call_record(validationToken):
    data = {"validationToken": validationToken}
    return data

The returned data variable looks like:

{'validationToken': 'Validation: Testing client application reachability for subscription Request-Id: c69b04df-f3d3-411c-8ceb-7f1ad8b7a927'}

Can someone help

Upvotes: 1

Views: 1204

Answers (2)

Lazloo Xp
Lazloo Xp

Reputation: 988

I found the awnser myself. Here function that works:

@app.post("/")
def read_call_record(validationToken):
    return Response(content=validationToken, media_type='text/plain')

Upvotes: 0

Marc LaFleur
Marc LaFleur

Reputation: 33094

Your code needs to Url Decode the validationToken query parameter and return it back to Graph.

From the documentation, your response must happen within 10 seconds with the following properties:

  • A status code of HTTP 200 OK.
  • A content type of text/plain.
  • A body that includes the URL decoded validation token. Simply reflect back the same string that was sent in the validationToken query parameter.

Important: If the client returns an encoded validation token, the validation will fail.

Upvotes: 2

Related Questions