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() {
getAndParse('GET');
}
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 ' +
EncodingUtil.base64Encode(headerValue);
request.setEndpoint(serviceEndpoint);
request.setMethod('GET');
request.setHeader('Content-Type', 'application/json');
// Header info with remote server user name and password
request.setHeader('Authorization', authorizationHeader);
// timeout in milliseconds
request.setTimeout(120000);
HttpResponse res = http.send(request);
System.debug(res.getBody());
this.response=res.getBody();
}
}
and vf...
<apex:page controller="GetRestfulExample" action="{!fetchData}" contentType="text/plain">
{!response}
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!