Rest Command POST Payload didn't work

Hi,

I have rest command script like this:

mainroom_switch:
    url: 'https://website.com/api'
    method: POST
    headers:
      accept: 'application/json; charset=UTF-8'
      content_type: 'application/json; charset=utf-8'
    content_type: 'application/x-www-form-urlencoded'
    payload: '{"state":"1"}'

And PHP Code like this:

$request = file_get_contents('php://input');
$payload = json_decode($request, TRUE); 
$state = $payload->state;

//insert into database
$sql = "INSERT INTO tb_sensor VALUES (NULL, '$state',, NULL, NULL)";
mysqli_query($conn, $sql);

There is no problem with query, i have tested it without payload with the same data.
I also have tested with jsontest website, it works.

$url = 'http://echo.jsontest.com/state/1';
$request = file_get_contents($url);
$payload = json_decode($request, TRUE); 
$data = $payload->state;

But with payload from rest command, a new row was added but it returned zero. Can someone help me?

Thanks

Why?
Remove the second one which, I assume, is taking precedence and is wrong.

I’ll try, thanks…

Did you get lucky? Iam looking for a automation like this.