0

I am trying to subscribe to notifications from Outlook Mail API. However I keep getting a 400 error. Ref: msdn.microsoft.com/en-us/office/office365/api/notify-rest-operations

$url = 'outlook.office.com/api/v2.0/me/subscriptions';
$headers = array(
   "Authorization: Bearer ".$access_token , 
    "Accept: application/json",             
    "X-AnchorMailbox: ".$user_email         
  );
$curl = curl_init($url);

$data = '{
   "@odata.type":"#Microsoft.OutlookServices.PushSubscription",
   "Resource": "outlook.office.com/api/v2.0/me/messages",
   "NotificationURL": "mydomain.com/listener.php",  
   "ChangeType": "Created"  
}';

$headers[] = "Content-Type: application/json";
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
$response = curl_exec($curl);

I haven't setup my listener yet. Is the 400 error because of the listener? Or is it something else?. Seems like the authentication was successful

singularity
  • 99
  • 2
  • 9

1 Answers1

0

There are two issues with this subscription request 1- Outlook/Office365 notifications requires secure channel; i.e. NotificationURL has to be 'https'. This is probably the reason for your 400 error. 2- NotificationURL has to be up and running as the service performs validation of this URL before accepting the subscription.

Please docs https://msdn.microsoft.com/office/office365/APi/notify-rest-operations or getting started concepts https://dev.outlook.com/RestGettingStarted/Concepts/Webhooks for more information.

Thanks.