Error 400 Api post server side scripting

When trying to post to a API using server-side scripting, I get error 400. When I copy the request to the API Docs, it works.

Here is the error message:

{ error:
   { code: 400,
     context: null,
     message: 'No record(s) detected in request. Please make sure record(s) are wrapped in a \'resource\' tag. Example: {"resource":[{"record":1},{"record":2}]}',
     status_code: 400 } }

Here is the code:

var rows = [];
    for (var item in c) {
        rows.push({'id': id, 'id2': parseInt(c[item], 10) });
    }, {"resource": rows }, null, function(body) {
        var results = JSON.parse(body);

Any help would be appreciated.