I want to create a webhook to listen for changes in excel files. This is the code I have:
{
"changeType": "updated",
"notificationUrl":"xxx.com/notificationClient/",
"resource":"me/drive/root",
"expirationDateTime":"2024-04-06T23:09:16Z",
"clientState": "microsoft_graph"
}
The problem is that I am getting the following error:
"message": "Subscription validation request failed. Response must exactly match validationToken query parameter.",
The code for the notificationUrl page is as follows:
<?php
// Check if the request is a validation request (GET)
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['validationToken'])) {
// The validation request must respond with the validation token
$validationToken = $_GET['validationToken'];
$validationToken = urldecode($validationToken);
// Set the content type to text/plain
header('Content-Type: text/plain');
// Returns the validation token
echo $validationToken;
http_response_code(200);
} else if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Process the actual change notification (if necessary)
// Your logic for handling the change notification goes here
echo 'Notification received successfully.';
http_response_code(200);
} else {
// If the request is neither GET nor POST, respond with a 405 status code (Method not allowed)
http_response_code(405);
}
I wonder if this error is shown because I use a token from a personal Microsoft account or because it occurs?