Search code examples
phpsmartthingstuya

What is Tuya expecting for the time header in API calls?


I'm trying to interact with the Tuya API from a PHP webapp.

I have authenticated the user and now have the code which is returned from Tuya. I now need to submit that via the Authorisation Management API to get an authorisation for subsequent API requests.

Following is the code I'm using to make the request to the Authorsiation Management API:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://openapi.tuyaeu.com/v1.0/token?grant_type=2');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('client_id: MY_TUYA_CLIENT_ID', 't: ' . time(), 'code' . $_GET['code']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

No matter what I try, the error I receive is always error code 1013 "request time is invalid".

I believe the parameters need to be passed in the header, hence why I'm using CURLOPT_HTTPHEADER to pass each of the values, but I suspect that is not correct.

Does anyone have an idea what I'm doing wrong here?


Solution

  • time() * 1000

    They need 13 character timestamp.