Home > Net >  ThingsBoard Rulechains - REST API Call with Form URL encoded Body
ThingsBoard Rulechains - REST API Call with Form URL encoded Body

Time:01-04

We would like to fetch data from an external REST API with ThingsBoard Rulechains. In order to this, first we need to get an Auth token for further requests to the API. It is required by the API to send an POST Request with Form URL encoded body like the following:

{
 "grant_type": "password",
 "username": "XXX",
 "password": "XXX
}

If we try this with ThingsBoard rulechains the following error is returned:

org.springframework.web.client.HttpClientErrorException$UnsupportedMediaType: 415 Unsupported Media Type: [no body]

We also tried setting the Content-Type Header Property to application/x-www-form-urlencoded

In Tools like Insomnia or Postman this works, if we explicitly define the Body to Form URL encoded, but ThingsBoard doesn't have this option.

CodePudding user response:

There are several posts (one and two) on the official bugtracker where one suggest to add fake parameters in the front and back of your data and set content type to x-www-form-urlencoded

var vMsg = "start=start&grant_type=password&username=XXX&password=X&end=end";
return {msg: vMsg, metadata: metadata, msgType: msgType};
  • Related