Tuya API Stuck at 1004 Invalid sign

149 views Asked by At

Can anyone help me please?..I'm new to this and I managed to get the token (I can print $access_token and it matches with the one on postman) but I cant get past the error 1004. I went all through the documentation but I cannot find what I'm doing wrong {"code":1004,"msg":"sign invalid","success":false,"t":1699465157510,"tid":"bdb815d97e5d11eea3b2361f03176748"}

<?php include "Sdk.php"; date_default_timezone_set('Europe/Malta');

$config = array(
    "clientID"  => "YOUR_CLIENT_ID",
    "accessUrl" => "https://openapi.tuyaeu.com",
    "secret"    => "YOUR_SECRET_ID",
    "nonce"     => "", );

$request = new SendClient($config); $access_token = $request::$AccessToken;

$device_id = "YOUR_DEVICE_ID"; $time = time()*1000; $client_ID = "YOUR_CLIENT_ID"; $secret = "YOUR_SECRET_ID"; $stringToSign = $client_ID . $time; $signature = strtoupper(hash_hmac("sha256", $stringToSign, $secret));

$code = "switch_1"; $value = true;

$commands = [   "commands" => [ [
      "code" => $code,
      "value" => $value
    ]   ] ];

$url = "https://openapi.tuyaeu.com/v1.0/devices/{$device_id}/commands"; $headers = [   "access_token: {$access_token}",   "Content-Type: application/json",   "t: {$time}",   "client_id: {$client_ID}",   "sign: {$signature}",   "sign_method: HMAC-SHA256" ];

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($commands));  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch); curl_close($ch);

echo $output; ?>

Tried to follow all Tuya documentation

1

There are 1 answers

1
Niskahiki On

If you have checked all the documents related to the "sign invalid" error: https://developer.tuya.com/en/docs/iot/new-singnature?id=Kbw0q34cs2e5g. Then I would recoment you to post your error and code to the Tuya forum: https://www.tuyaos.com/viewforum.php?f=22. There you can more easially find people that can help you with you problem related to the Tuya API error.