function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suraj SinghSuraj Singh 

ERROR: Integrating Salesforce to one-Drive.

Response code: 400
Error,  { "error": { "code": "BadRequest", "message": "The MIME type 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2' requires a '/' character between type and subtype, such as 'text/plain'.", "innerError": { "request-id": "822a994e-6ef7-4c4c-bd27-5b96186165f0", "date": "2017-04-13T13:44:15" } } }

        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('Authorization', 'Bearer '+ accessToken);
        req.setEndpoint('https://graph.microsoft.com/v1.0/me/drive/root');      
        HttpResponse res = h.send(req);
VivekShindeVivekShinde
Do not set the 'Content-Type' parameter in the header and check if this works. If it doesn't, you have to go through the API documentation of OneDrive to know the exact parameters for making a GET request.
Suraj SinghSuraj Singh

@VivekShinde
It doesn't work,
Problem is not the content-type, problem is thatm if you use any rest api client (like ARC), it will works fine.
Although it works in JS, when we made a request from JS on VF page, it works.
But only in Apex code it does not work.
 

SaketJoshiSaketJoshi
Can you confirm whether the content-type header is being set as expected? You can do a System.debug('header' + req.getHeader('Content-Type')); Also confirm the character cases in the headers that you are sending from the OneDrive dev documentation
Suraj SinghSuraj Singh
I had checked it, it was working as expected to done so. 
Actually, header is an optional for it. if you try it without header it will also work perfect.

 
Suraj SinghSuraj Singh
@SaketJoshi, But the issue was reamains same, it will not work with apex code.
SaketJoshiSaketJoshi
Can you provide a link of the API documentation for OneDrive? The one that I found does not contain the endpoint that you have used in your request. This is the one that I found on the internet - https://developer.microsoft.com/en-us/graph/docs
Suraj SinghSuraj Singh
@SaketJoshi, Yes i had checked it, but issue remains same... it will not work for apex code. 
It will only work in JS or on any rest api client (like ARC).