Microsoft graph Unable to read JSON request payload

僤鯓⒐⒋嵵緔 提交于 2021-01-28 01:53:00

问题


I'm trying to create subscriptions with microsoft graph in php, however I am unable to see what is going wrong at this point.

The code is breaking at the following:

protected $http_subscribe = "https://graph.microsoft.com/v1.0/subscriptions";

public function getSubscriptions()
{
    if(empty($this->token)) {
        dd('no token supplied'); //some debugging
    }

    $date = $this->endTimeDate->format('Y-m-d'); //This is Carbon date

    $time = $this->endTimeDate->format('H:i:s.u');

    $response = $this->client->request('POST', $this->http_subscribe, [
        'headers' => [
            'Authorization' => 'Bearer ' . $this->token,
            'Content-Type' => "application/json"
        ], 'form_params' => [
            "changeType" => "created,updated",
            "notificationUrl" => "https://website.test/notify",
            "resource" => "me/mailFolders('Inbox')/messages",
            "expirationDateTime" => $date.'T'.$time,
            "clientState" => "secretClientValue"
        ]
    ]);

    dd($response);
}

The full error I'm getting is:

"""
{\r\n
  "error": {\r\n
    "code": "BadRequest",\r\n
    "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",\r\n
    "innerError": {\r\n
      "request-id": "063d9947-80fd-461d-a70e-q0bd8eee9d56",\r\n
      "date": "2018-08-07T08:20:54"\r\n
   }\r\n
  }\r\n
}
"""

Now I get what the error says, my json would be invalid, however this array is in correct json format, I'm using Guzzle as my Client.


回答1:


You should use json option. Try this:

$response = $this->client->request('POST', $this->http_subscribe, [
   'headers' => [
       'Authorization' => 'Bearer ' . $this->token,
   ],
   'json' => [
       "changeType" => "created,updated",
       "notificationUrl" => "https://website.test/notify",
       "resource" => "me/mailFolders('Inbox')/messages",
       "expirationDateTime" => $date.'T'.$time,
       "clientState" => "secretClientValue",
   ],
]);


来源:https://stackoverflow.com/questions/51722614/microsoft-graph-unable-to-read-json-request-payload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!