Apigee BaaS returning null_pointer when using Edge HttpClient to insert entity into collection

Not applicable

When trying to insert an entity to a BaaS collection. I am getting a null_pointer using the Edge JavaScript HttpClient object, but when posting from external application no errors exists with same data.

var req = new Request(
      'https://api.usergrid.com/[ORGID]/[APPID]/[COLLECTION]?client_id=XXXX&client_secret=XXXX', 
      'POST',
      {}, 
      serializeQuery({'name':'value'})
);
    req.port = 443;

  var exchange = httpClient.send(req);
  exchange.waitForComplete();
  
  var resp = exchange.getResponse();
  
  if (exchange.isSuccess()) {
    var responseObj = exchange.getResponse().content.asJSON;
    if (responseObj.error) {
    	throw new Error(resp.content);
    }
  } else if (exchange.isError()) {
  	throw new Error(exchange.getError());
  }
headers
{}
content
{"error":"null_pointer","timestamp":1439482031492,"duration":0,"exception":"java.lang.NullPointerException"}
status
500
Solved Solved
1 2 455
1 ACCEPTED SOLUTION

Not applicable

Solution was to send the body as a JSON string

var req = new Request(
      'https://api.usergrid.com/[ORGID]/[APPID]/[COLLECTION]?client_id=XXXX&client_secret=XXXX', 
      'POST',
      {}, 
      JSON.stringify({'name':'value'})
);

View solution in original post

2 REPLIES 2

Not applicable

Solution was to send the body as a JSON string

var req = new Request(
      'https://api.usergrid.com/[ORGID]/[APPID]/[COLLECTION]?client_id=XXXX&client_secret=XXXX', 
      'POST',
      {}, 
      JSON.stringify({'name':'value'})
);

Dear @Chad S ,

Welcome to Apigee Community 🙂 Thank you for taking time to share solution with everyone.Sure, It will be helpful for others.

Cheers,

Anil Sagar