I have been trying to call an external service from apex. My Attempts so far to view the incidents ..

public class GetRestfulExample {
 private final String serviceEndpoint= 'https://devxxxx.service-now.com/api/now/table/incident.do';
public String Response { get; set;}
public String Headers { get; set; }

public void fetchData() {

public void getAndParse(String GET) {

// Get the XML document from the external server
Http http = new Http();
HttpRequest request = new HttpRequest();
String userName = 'xxx';
  String password = 'xxxx';

  // Specify the required user name and password to access the endpoint 
  // As well as the header and header information 
  Blob headerValue = Blob.valueOf(userName + ':' + password);
  String authorizationHeader = 'BASIC ' +

  request.setHeader('Content-Type', 'application/json');
  // Header info with remote server user name and password
  request.setHeader('Authorization', authorizationHeader);
  // timeout in milliseconds       

  HttpResponse res = http.send(request);


and vf...

 <apex:page controller="GetRestfulExample" action="{!fetchData}" contentType="text/plain">

I get this error and can't find where the headers are located...

{"error":{"message":"Unsupported value for header: Accept=text/html, image/gif, image/jpeg, *; q=.2, /; q=.2","detail":"Unsupported value for header: Accept=text/html, image/gif, image/jpeg, *; q=.2, /; q=.2 Check logs for error trace or enable glide.rest.debug property to verify REST request processing"},"status":"failure"}

I'm a beginner for using rest api, I would be grateful if I'm pointed to the right direction.

Thanks in advance!


Per the documentation of the Service Now API you MUST set the 'Accept' header for a GET request so add


Each of the supported methods can be overridden if you set the X-http-method-override header. The Accept and Content-Type request headers are required for proper data formatting. These request headers have the following valid values:

Accept: application/json, application/xml Content-Type: application/json, application/xml POST, PUT, and PATCH operations require you to provide both headers. The GET and DELETE operations require only the Accept header. Failing to provide the required headers results in a 400 Bad Request error.

try adding


Also, here is a known working API from Apex, although the endpoint API requirements may be a bit different.

HttpRequest req = new HttpRequest();
Http http = new Http();

Blob headerValue = Blob.valueOf(credentials.get('Username') + ':' + credentials.get('Password'));
String authorizationHeader = 'BASIC ' +
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');


String url = ....;


HTTPResponse resp = http.send(req);
  • I have included "Accept", but there's no change – MnZ Oct 20 '15 at 16:03
  • @MnZ - You previously said this did not help, is there anything I should add to the answer to make it more useful since you marked it as accepted? – Eric Nov 13 '15 at 14:47

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.