2

I'm creating a controller for lights using thingsboard. I need to change device's telemetry data (thingsboard) using rest put request

$.post("http://<ip_here>:8080/api/v1/<device_accesscode_here>/telemetry",{ selectedPreset:2 });

REST calls work using swagger.io and postman, but when calling from widget or any other web page, request returns 400.

Can't seem to find solution to this and url is correct. i have tried both $.post and $.ajax styles.

Quirosaur
  • 41
  • 4

1 Answers1

2

YAY! i got it working!

for some reason, only XHR approach worked..

var data = "{\"selectedPreset\":\"2\"}";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
console.log(this.responseText);
 }
});

xhr.open("POST", "IP HERE");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "33c35ded-140d-e016-fa35-ee8185d7bd44");

xhr.send(mydata);

i ripped this right out of postman.

Quirosaur
  • 41
  • 4