You need to sign in to do that
Don't have an account?
Alfia Quadri 11
how to use json on httprequest setBody
here is my apex class
I am getting this error
DEBUG|{"status":400,"error":"There was a problem in the JSON you submitted [5132df156cbaf320d27f8e06f3b61656]: logged with error code"}
PLEASE TELL ME HOW TO INCLUDE THE JSON???
public class makeCallOutIC1 {
public String getContent(String url){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.intercom.io/contacts/search/');
req.setMethod('POST');
String authorizationHeader = 'Bearer ' + 'd2222=';
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Intercom-Version', '2.6');
String body = '{'+
'"query": {' +
' "field": "last_seen_at", ' +
' "operator": ">", ' +
' "value": "1646149510", ' +
' }' +
' }';
req.setBody(body);
HttpResponse res = h.send(req);
return res.getBody();
}
}
I am getting this error
DEBUG|{"status":400,"error":"There was a problem in the JSON you submitted [5132df156cbaf320d27f8e06f3b61656]: logged with error code"}
PLEASE TELL ME HOW TO INCLUDE THE JSON???
public class makeCallOutIC1 {
public String getContent(String url){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.intercom.io/contacts/search/');
req.setMethod('POST');
String authorizationHeader = 'Bearer ' + 'd2222=';
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Intercom-Version', '2.6');
String body = '{'+
'"query": {' +
' "field": "last_seen_at", ' +
' "operator": ">", ' +
' "value": "1646149510", ' +
' }' +
' }';
req.setBody(body);
HttpResponse res = h.send(req);
return res.getBody();
}
}
Does the code fromhttps://salesforce.stackexchange.com/questions/288573/how-to-pass-json-in-set-body-using-rest-and-method-post-in-apex help?
Thanks
you can use JSON Generator to fulfill your requirement
Link for JSON Generator : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsongenerator.htm
Kindly mark this as best answer if this solves your your issue .
Thanks,
karthik