I'm trying to serialize to IP to a POST statement but it's giving me this error: message: Json Deserialization failed on token 'null' and has left off in the middle of parsing a row. Will go to end of row to begin parsing the next row errorCode: INVALID_FIELD

This is the body of the JSON:


this is the code:

public class ipWrapper{
    String Start;
    String EndIP;

ipWrapper ip1 = new ipWrapper();
ip1.Start = '';
ip1.EndIP = ip1.Start;

ipWrapper ip2 = new ipWrapper();
ip2.Start = '';
ip2.EndIP = ip1.Start;

List<ipWrapper> listIP = new List<ipWrapper>();

String bodyToFix = JSON.serialize(listIP);
system.debug('bodyToFix: ' + bodyToFix);
String body = bodyToFix.replace('EndIP', 'End');
system.debug('body: ' + body);
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');      
Http httpreq = new Http();

HttpResponse res;

enter image description here

1 Answer 1


This endpoint (and most other endpoints in Tooling API) can only insert one entity in a POST request. So you will have to only send in one object instead of an array.


However, if you wish to create multiple entities/records in the IPRange object or other objects in a single request, consider using the Composite API.

Hit this endpoint /services/data/v51.0/tooling/composite, with the below composite request - which has 2 sub requests, one for each IPRange.

     "body": {"Start":"","End":""},
     "body": {"Start":"","End":""},

So your Apex class could look something like this

public class CompositeRequestWrapper{
    Boolean allOrNone;
    List<CompositeRequest> compositeRequest ;

public class CompositeRequest{
    public String method;
    public Map<String, String> body;
    public String url;
    public String referenceId;

public static void createRequest(){
    CompositeRequestWrapper crw = new CompositeRequestWrapper();
    crw.allOrNone = true;
    List<CompositeRequest> requests = new List<CompositeRequest>();
    CompositeRequest cr = new CompositeRequest();
    cr.method = 'POST';
    cr.url = '/services/data/v40.0/tooling/sobjects/IPRange/';
    cr.referenceId = 'ref1';
    Map<String, String> o = new Map<String, String>();
    o.put('start', '');
    o.put('end', '');
    cr.body = o;

    CompositeRequest cr2 = new CompositeRequest();
    cr2.method = 'POST';
    cr2.url = '/services/data/v40.0/tooling/sobjects/IPRange/';
    cr2.referenceId = 'ref2';
    o = new Map<String, String>();
    o.put('start', '');
    o.put('end', '');
    cr2.body = o;

    crw.compositeRequest = requests;
    String bodyToSend = JSON.serialize(crw);
    HttpRequest req = new HttpRequest();
    req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
    req.setHeader('Content-Type', 'application/json');      
    Http h = new Http();

    HttpResponse res = h.send(req);
  • thank you very much for your answer. Ive tried to find the continuation of your code but I cannot implement it Aug 12, 2021 at 10:08
  • @JulioDidierMaciel I just updated my answer to include the full code. Aug 12, 2021 at 10:14
  • tried to execute your code on a anonymous block but didnt create the IPs. Aug 12, 2021 at 10:19
  • Strange - I tried this code in a new scratch org, and it created the Trusted IPs under Network Access. Are you seeing any errors in the HTTP response? Oh by the way - The code above goes into an Apex class, and then you need to call the createRequest() method. If you're running it as anonymous, you will need to move all the code outside the createRequest() method. Aug 12, 2021 at 10:48
  • or just call the createRequest() at the end. Aug 12, 2021 at 10:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .