Reputation: 55
I receive the following error when I make an PUT API CALL to upload a document to OneDrive using Microsoft Graph API. It was working earlier, it has stopped working suddenly.
{\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\": \"133ac360-740d-4823-9a93-1090616d925b\",\r\n \"date\": \"2016-04-11T06:24:59\"\r\n }\r\n }\r\n}
The code which I am executing is
using (var client = new HttpClient())
{
string url = https://graph.microsoft.com/v1.0/me/drive/root:/Test.xslx:/content
using (var request = new HttpRequestMessage(HttpMethod.Put, url))
{
string headerAcceptTest = "application/json";
MediaTypeWithQualityHeaderValue headerAccept = new MediaTypeWithQualityHeaderValue(headerAcceptTest);
request.Headers.Accept.Add(headerAccept);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Content = new ByteArrayContent(data);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
using (var response = await client.SendAsync(request))
{
if (response.StatusCode == HttpStatusCode.Created)
{
string responseContentAsString = await response.Content.ReadAsStringAsync();
}
}
}
}
Any clue where am I going wrong?
Upvotes: 2
Views: 2823
Reputation: 879
There was an issue with a new build that was rolled out over the weekend, and we have now reverted it. The issue should now be resolved.
Upvotes: 3
Reputation: 1319
I saw a change in behavior of the One Drive API on uploading a file to One Drive.( https://dev.onedrive.com/items/upload_put.htm) , this API call fails with error.
Sample 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": { "request-id": "7e734f93-3033-4bb4-a433-c5d9c400f46e", "date": "2016-04-11T02:33:35" } } }
Actually it was working fine until 8th April 2016, The Documentation says its text/plain content type , why is this expecting application/json
Upvotes: 3