0

I have created a named credential that points to the Microsoft graph API.

My credential has been authenticated successfully but when I try to use it from Apex it fails. I am unable to debug , The code I am using is :

HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Azure_AD/users/xyz?api-version=1.6');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());


I am getting the below error:

08:19:50:598 USER_DEBUG [7]|DEBUG|<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>Request_BadRequest</m:code><m:message xml:lang="en">The MIME type 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2,application/json;odata=minimalmetadata;q=0.001' requires a '/' character between type and subtype, such as 'text/plain'.</m:message></m:error>
3

I had the same issue and managed to solve it by adding

req.SetHeader('Accept','application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.