msgraph-sdk-php icon indicating copy to clipboard operation
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

Open mankowitz opened this issue 2 years ago • 2 comments

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

mankowitz avatar Sep 24 '21 21:09 mankowitz

did you solve that?

muhamedRadwan avatar Feb 22 '22 03:02 muhamedRadwan

@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.

Ndiritu avatar Feb 22 '22 08:02 Ndiritu

No further correspondence from OP. Uploading CSVs works in v2 Preview as well.

Ndiritu avatar Oct 06 '22 08:10 Ndiritu