OK, the above code works fine and once run, I see valid output showing whether an IP got added successfully or what was the failure message.

Now, I'm trying to implement the same functionality in NodeJS.

To do that, I have successfully created functions to generate JSESSIONID (so that I can use it to perform multiple REST/API call operations, rather than creating a new session each time for any operation), successfully deleting a JSESSIONID (i.e. to logoff/out from Imperva session so that I don't hit the limit) and to successfully search an IP in Imperva system if it has been previously added.

Using the above shell script logic, I have written the following NodeJS code to add a new OS Connection IP in Imperva using Rest/API, but I'm getting an error.

2. How to pass CURL's -d option {...} body parameters in the NodeJS code above, like I used it in the shell script.

PS: Changing POST to GET (method), assures that the code is fine syntax wise as it successfully shows the IP (with GET operation) with the above NodeJS code.

So, it's failing only when I use POST (i.e. when I'm trying to create an IP) -vs- GET (which I use to find an IP exist or not). I checked as per the Imperva API doc, the response comes in JSON format. Not sure if due to missing bullet# 2 question, I'm getting this Syntax error with POST.

Now, both options and data will be sent to httpHelp(options,data) and it'll work.

The above is just an dummy data value. Usually I'd pass valid host-name in the JSON object.

Never thought that not setting the data variable would result in this syntax error.

Other thing, I was missing BIG time was the value for 'Content-Type' inside headers variable. That was the reason, the error message was having "<" bracket in it (as by default it looks for a <body>...</body> section containing some XML format but in our case, the HTML response contained or was getting returned in JSON { ... } format way for the body section. That's why it was showing an error for unexpected token <.

As per the API doc, it should have been "JSON" type, thus changed that line to