Update Variable throw Arduino IoT Cloud API using php,javascript

Hello, I trying to update variables values throw Cloud Api. First I want you to know that all script which is working with token generation, reading values and etc. is working perfect! I just cant update values.

  1. I can not find anywhere what does: 'X-Organization: ' . $xOrganization, mean's and where I can find its UUID. I have maker plan not free and even in it I can't find it.

here is one of the example of my code:

echo $url = "https://api2.arduino.cc/iot/v2/things/$thingId/properties/$config_id/publish";
$headers = array(
    "Content-Type: application/json",
    "Authorization: Bearer $token"
);

$data = array(
    "value" => "$value",
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);

echo "
    $response
    $httpStatus
    $curlError
";

if ($response === false) {
    echo "Error: " . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);

I get this error:

https://api2.arduino.cc/iot/v2/things/0eef551e-5d9a-49fe-a8d5-xxxxxxxxxxx/properties/ac76ce1b-e2d0-41a4-9d33-xxxxxxxxx/publish {"id":"m5QMkvcx","code":"unauthorized","status":401,"detail":"not allowed to publish the property thingID=0eef551e-5d9a-49fe-a8d5-d7xxxxxxxx","meta":{"requestId":"8VXXTgQOyN-6477162"}} 401 {"id":"m5QMkvcx","code":"unauthorized","status":401,"detail":"not allowed to publish the property thingID=0eef551e-5d9a-49fe-a8d5-xxxxxxxxx","meta":{"requestId":"8VXXTgQOyN-6477162"}}

I know 100% that my token is valid because before sending this request its check device status, using this exact token and it valid for 3 minutes.

I know that here is a lot of very smart guys, required your help!

I have this error:

{
"id": "8okDRPTK",
"code": "unauthorized",
"status": 401,
"detail": "not allowed to publish the property thingID=0eef551e-5d9a-49fe-a8d5-d7xxxxxxx",
"meta": {
"requestId": "NCM4tnrKJF-6627637"
}
}

do not understand why or how I should allowed or even from where..?

Hi!

Not an expert in PHP, so not sure if I can help with the details of the code.

What I would suggest is that you test the API calls externally and not inside your code. That will be simpler for you to debug.

For instance, you can use postman, which is very convenient if you want to tweak certain parameters. Here you have a link describing how to use it with the IoT Cloud API:

Alternatively, you can just use curl to test if your request is correct.

I'm sure you have already done this too, but please, double check that the IDs are correct and they belong to the account for which you get the token.

I hope this helps.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.