0

I am using office365 app and referenced from https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations#Createandsendmessages and https://dev.outlook.com/RestGettingStarted/Tutorial/php create a function:

function reply_to(){
    $comment =array("Comment"=> $_POST['comment']);

    $url="https://outlook.office365.com/api/v1.0/me/messages/'".$_POST['messeg_id']."'/reply";

    $data=OutlookService::makeApiCall($_SESSION['access_token'],'POST',$url,$comment);
    print_r($data);     
}

and always getting the same error

Array ( [errorNumber] => 400 [error] => Request returned HTTP error 400 ).

I don't know what I am doing wrong I have checked multiple times.

Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99

1 Answers1

0

A couple of problems:

  1. Remove the single-quotes ' around your message ID in the URL.
  2. JSON encode the $comment array before passing it to makeApiCall like so: $comment = json_encode(array("Comment"=> $_POST['comment']));

If you don't JSON encode, then cURL sends the data a form-encoded, rather than as a JSON entity in the body. The server rejects it with a 400 because it's invalid JSON.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • Thanks for reply, Now i am removed single quotes from URL but again the same error occurred. function reply_to(){ $comment =array("Comment"=> $_POST['comment']); $url="https://outlook.office365.com/api/v1.0/me/messages/".$_POST['messeg_id']."/reply"; print_r($url); $data=OutlookService::makeApiCall($_SESSION['access_token'],'POST',$url,$comment); print_r($data); } – gopendra dwivedi Jul 20 '15 at 15:51
  • Ok. I updated my answer after trying it here. cURL doesn't send the array as JSON by default. – Jason Johnston Jul 20 '15 at 16:54
  • ok, but if i am sending the normal php array like array("Comment"=> $_POST['comment']) this shows the same error – gopendra dwivedi Jul 20 '15 at 18:11
  • Right. That's the problem. A non-encoded PHP array gets transmitted as form-encoded data, which is not what the mail API expects. It has to be JSON-encoded. – Jason Johnston Jul 21 '15 at 13:59
  • i do this but it also not working. Giving same error. i.e. Array ( [errorNumber] => 400 [error] => Request returned HTTP error 400 ). – gopendra dwivedi Jul 25 '15 at 20:01