I'm creating subscription for webhooks. For implementation I'm using https://github.com/microsoftgraph/msgraph-sdk-php
package.
Below is the implementation of functionality
class WebhookRepository
{
public function __construct()
{
$this->graph = new Graph();
}
public function subscribe($accessToken)
{
try {
$this->graph->setAccessToken($accessToken);
$sub = new Model\Subscription();
$sub->setChangeType("created,updated");
$sub->setNotificationUrl(notificationUrl);
$sub->setResource("/me/mailfolders('inbox')/messages");
$sub->setClientState('SecretClientState');
$dateTime = new Carbon();
$dateTime->addDays(3);
$sub->setExpirationDateTime($dateTime);
$subResult = $this->graph->createRequest("POST", "/subscriptions")
->attachBody($sub)
->setReturnType(Model\Subscription::class)
->execute();
} catch (\Exception $e) {
}
}
}
And when I'm executing this request then it send me request to the notificationUrl
with validateToken. As mensioned in documentation I'm sending same response as give in step 2
https://learn.microsoft.com/en-us/graph/webhooks#managing-subscriptions
And there is the implementation of notify functionality
public function notify(Request $request)
{
$token = $request->input('validationToken');
$response = response()->make($token, 200);
$response->header('content-type', 'text/plain');
return $response;
}
and this notify function is returning 200 response code with content type text/plain
. with validateToken. But in subscription response I'm getting this error
string(246) "Client error: `POST https://graph.microsoft.com/beta/subscriptions` resulted in a `400 Bad Request` response:
{
"error": {
"code": "InvalidRequest",
"message": "Subscription validation request timed out.",
"inner (truncated...)
"
I'm stuck here. not getting any example for notify function how to send validation token in request.
FYI: I'm using this in Laravel 5.5
Framework.