Calling API from post process


#1

Hi,
how to create record in post process script ?

I am trying to add a record to employee table after user register
and I was able to build record with fields required for employee entry in

var record = {
has valid fields // i have tested it using client side api call.
}

  var result = platform.api.post("mysql/_table/employee", {resource: [record]});
  if (result.status_code !== 200) {
      throw new Error(JSON.stringify(result.content.error.message));
  }

this is throwing some wired error in console log,

any idea how do I call post method from scripting ?


#2

Vinod, what is the error?


#3

looks like it was known issue in 2.2 to call api’s from node script. (FYI, it was logging actually api function instead of executing it)

after upgrade I am still having issue, here is the code i am using

    platform.api.post("mysql/_table/employee",{resource : [record] }, '', function(body, response){
            console.log(response.statusCode + " " + response.statusMessage);
            event.setResponse(JSON.parse(body), response.statusCode, 'applicaton/json');
        });

above code is giveing me 400 Bad Request in the log and that’s all it says it doesn’t say anything else like invalid path or parameters. I got the above example from http://wiki.dreamfactory.com/DreamFactory/Tutorials/Node_service_monetization

any idea how to call api from node script ?


#4

Bad request means the api call is formatted incorrectly (usually the payload.) I can’t see the rest of your script, but assuming record is a variable:
this: {resource : [record] }
should be this: {"resource" : [record] }