msgraph-sdk-php
msgraph-sdk-php copied to clipboard
Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format
I am trying to upload a file to sharepoint as follows:
$graph = new Graph();
$graph->setAccessToken($access_token);
$response = $graph->createRequest("PUT", "/drives/$drive_id/items/root:/$saveAsFileName:/content")
->upload($localFilename);
The response I'm getting is:
Client error: PUT https://graph.microsoft.com/v1.0/drives/b!TrzSHNU_E0aYGOsFVa7g_1vG63BXZs8dPFZhFEdcxtEiu9kndQKfaSwyE1jiB/items/root:/AbilityBeyond/AbilityBeyond_2021-09-24T17:31:49.7986800Z.csv:/content
resulted in a 400 Bad Request
response:
{"error":{"code":"BadRequest","message":"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.","innerError":{"date":"2021-09-24T20:59:20","request-id":"3b931e78-59a5-495f-b4ca-804f3130525a","client-request-id":"3b931e78-59a5-495f-b4ca-804f3130525a"}}}
I'm using php 8.0.10; msgraph-sdk-php 1.39.0
did you solve that?
@muhamedRadwan @mankowitz thanks for reporting this.
I'm unable to reproduce this behaviour. Please try calling addHeaders(['Content-Type' => 'text/csv'])
before upload()
or with the relevant MIME type and let me know if it works.
No further correspondence from OP. Uploading CSVs works in v2 Preview as well.