skip to Main Content

When uploading offline conversion data to Facebook’s API there is a limit of 2,000 events per API call.

In order to upload JSON objects with over 2000 events they would need to be split up into smaller objects and POST’ed one at a time.

How can this be achieved?

Thanks.

2

Answers


  1. Chosen as BEST ANSWER

    Thank you etemple1 for your answer.

    Great example of my trying to find a workaround when a solution already exists.

    For anyone looking to split a json object here is the method i used.

    with batchSize being the size of each resulting json (except for the last which cuts off when reaching the end of data.

        var batchSize = 1900;
        var total = jsonObj.length;
    
        for (var j = 0; j <= Math.floor(total/batchSize); j++) {
            var data = [];
            var batchStart = j*batchSize;
    
            for (var i = batchStart; i < batchStart+batchSize; i++) { 
                var obj = {};
                var index = i;
    
                obj.currency = jsonObj[index].someFieldFoo;
                data.push(obj);
                if (index + 1 >= jsonObj.length) {
                    break;
                }
                // console.log(data);
    
            };
        };
    

  2. Per the docs, you can make batch requests by building a JSON object to describe each individual operation you’d like to perform. You can perform up to 50 operations in one batch request, but each operation counts as a single call. E.g. 50 operations in a single batch request counts as 50 requests against your quota.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search