Search code examples
onedrivemicrosoft-graph-api

Microsoft Graph API One Drive Unable to read JSON request payload


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?


Solution

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