0

Javascript code in zapier

 var registerData="{'uuID':'"+uuID+"','notifTitle':'"+notifTitle+"','notifBody':'"+notifBody+"','redirectUrl':'"+redirectUrl+"','notifIconUrl':'','notifyToFlag':'INDIV','source':'API'}";

   var data = JSON.stringify({"requestData":registerData});

In Action Class i am getting the request data

requestData=request.getParameter("requestData");

JSONObject jsonObject = (JSONObject) new JSONParser().parse(requestData);//getting exception

In request header

Content-Length: 231

Accept-Encoding: gzip, deflate

Accept: application/x-www-form-urlencoded

User-Agent: Zapier

Connection: keep-alive

Content-Type: application/x-www-form-urlencoded

request data which it is sending

{"requestData":"{'uuID':'APIKEY','notifTitle':'hiii','notifBody':'hiii','redirectUrl':'https://zapier.com/app/editor/7942969/nodes/7942970/fields','notifIconUrl':'','notifyToFlag':'INDIV','source':'API'}"}

console log

{\"requestData\":\"{'uuID':'APIKEY','notifTitle':'hiii','notifBody':'hiii','redirectUrl':'https://zapier.com/app/editor/7942969/nodes/7942970/fields','notifIconUrl':'','notifyToFlag':'INDIV','source':'API'}\"}"

getting Exception

java.lang.NullPointerException\n\tat java.io.StringReader

ArK
  • 20,698
  • 67
  • 109
  • 136
Sanjog Mittal
  • 118
  • 2
  • 14
  • 1
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – 3kings Mar 30 '16 at 13:46
  • java.lang.NullPointerException\n\tat java.io.StringReader.(StringReader.java:50)\n\tat org.json.simple.parser.JSONParser.parse(JSONParser.java:79)\n\tat org.json.simple.parser.JSONParser.parse(JSONParser.java:75)\n\tat com.pushbiz.pushbizMaster.action.PushBizAction.saveAndSendNotification(PushBizAction.java:290)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat – Sanjog Mittal Mar 30 '16 at 13:46
  • So requestData is null, obviously. Would be helpful to know what the URL is. Typically, a URL would look something like this: `www.url.com/page?key=value&key2=value2` – Christopher Schneider Mar 30 '16 at 13:49
  • Hi sir it is a post request – Sanjog Mittal Mar 30 '16 at 13:50
  • 1
    You're using the wrong encoding. You're saying that you send `application/x-www-form-urlencoded` but you're sending a JSON string instead. You need to URL-encode your post parameters rather than JSON encoding. Other the `request.getParameter` call will not be able to retrieve the parameter - it doesn't even see any parameter because the encoding format is wrong. – Erwin Bolwidt Mar 30 '16 at 13:51
  • @ErwinBolwidt He is correct. Refer to this answer: http://stackoverflow.com/questions/6603928/should-i-url-encode-post-data?lq=1 – Christopher Schneider Mar 30 '16 at 13:52
  • 1
    @ChristopherSchneider What do you mean? If you agree with me you can simply upvote the comment. – Erwin Bolwidt Mar 30 '16 at 14:01
  • Thank you Sir, I got the answer it was to stringify the data...thank youuuuu – Sanjog Mittal Mar 30 '16 at 14:05

1 Answers1

1

This is caused by no "requestData" param, your submitted data is a JSON object itself. I think you should change your JS to

var data = 'requestData':JSON.stringify(registerData);
An Do
  • 309
  • 1
  • 8