HTTP POST with form data but content type application/json

I want to perform a HTTP POST request with form(?) data.

Function node:

msg.headers = {}
msg.method = "POST"
msg.url = "" 
msg.payload = {"email": "email","password": "pass"}
msg.headers["content-type"] = "application/json"
msg.headers["X-Requested-With"] = "XMLHttpRequest"
return msg

API documentation states that headers should be:

Content-Type : application/json
X-Requested-With: XMLHttpRequest

The info for the http request node states:

To encode the request as form data, msg.headers["content-type"] should be set to application/x-www-form-urlencoded.

With application/json I get authorisation failed, with the application/x-www-form-urlencoded it failed and expects application/json

How can I post this with the correct header(s) ?

A look in the API documentation confirms that the body of the POST request has to be JSON, like below to login and request a token

	"email": "",
	"password": "yourpassword"

In such case the content-type should be application/JSON.

The reply I got when testing the API was:


which confirms that the POST request is OK, it is jus the server that is not authorizing.

I was wondering about that.
What is the application/x-www-form-urlencoded used for?

In the case the body of the request will be like below, which is very similar to the query parameters of a GET request (key,values separated by &):


1 Like

Got it. makes sense.
I will contact the folks behind the api.

1 Like

Tried it via curl (should have done that earlier) and indeed same error.