I'm a beginner in webservices and future calls. I have been trying post parameters to an external system (ServiceNow). As of now I'm able to post a generic description field from Salesforce to ServiceNow.
Here's what I have tried so far..
trigger Case2ServiceNow on Case (after insert) {
for(Case c : [Select Id, RecordTypeId, RecordType.Name,Subject From Case Where Id IN : Trigger.new]) {
if(c.RecordType.Name == 'Incident'){
AuthCalloutPost.basicAuthCalloutPost();
// uniqueNames.add(c.Subject);
}
else{
System.debug('##false##');
}
}
}
here's the class...
public class AuthCalloutPost{
public String Response { get; set;}
@future(callout=true)
public static void basicAuthCalloutPost(String names){
HttpRequest req = new HttpRequest();
req.setEndpoint('xxx/api/now/table/incident');
req.setMethod('POST');
String postData = '{\"short_description\":\" Posting from Salesforce.com case trigger\"}';
req.setBody(postData);
req.setTimeout(120000);
String authorizationHeader = 'Basic xyz=';
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Accept', 'application/json');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
// this.response=res.getBody();
}
}
I'm trying to post Salesforce Case parameters to the ServiceNow like name, description. I would really appreciate if I'm pointed to the right direction. Thanks in advance.
UPDATE: when I comment //req.setBody(requestbody); and post this instead, it works! String postData = '{\"short_description\":\"Posting a Sentence\"}'; req.setBody(postData); I'm still not able to figure out the issue in Json generation.