Using the access token from the API to request thing properties.

I am currently creating an app using the MIT app inventor which needs to get data from the android cloud using its API [Documentation] . I have successfully obtained an access token (or auth token as they use in the documentation) but then when I try to make a request using this access token (say for a thing property), I get a 401 response meaning unauthorisation.

I was using the auth key by making a get request using:

"https://api2.arduino.cc/iot/v2/things/{thingid}/properties?access_token={the access token I had}"

I am trying to get the 200 response code indicating an okay request.

This is my first time using API requests so any help would be much appreciated.
Many thanks,
Harry

Hi Harryac5217! You're welcome :slight_smile: I don't know the MIT app inventor, but I can try to help you with Arduino IoT Cloud API. If you have rightly generated a Bearer token using your Client ID and Secret ID [see Doc], for listing the properties of a thing you need to launch this cURL request:

curl --request GET \
  --url https://api2.arduino.cc/iot/v2/things/{YOUR_THING_ID}/properties \
  --header 'Authorization: Bearer YOUR_TOKEN'

You need to pass the token in a header field. Please, keep me update if this command works or not.

That is absolutely awesome! It has worked a treat, thank you very much!

I have come across another problem. I am trying to use devicesV2UpdateProperties api but I am confused in the format to use in the body of the put method. The documentation uses name, hex and value but I am not sure how exactly they specify the change to the property's last value (especially as they describe hex then use a non-hex value).

Again, any help is much appreciated!

Hi :slight_smile: I'm not sure I have rightly understood: what do you want to do? What is your main goal? If you want to update a property value, so changing the board behavior (e.g. blinking the LED of a connected board using IoT Cloud API), you need to use propertiesV2Publish

curl --request PUT \
  --url 'https://api2.arduino.cc/iot/v2/things/{YOUR_THING_ID}/properties/{YOUR_PROPERTY_ID}/publish' \
  --header 'content-type: application/json' \
  --header 'Authorization: Bearer MY_TOKEN' \
  -d '{"value": "YOUR_VALUE"}'

If your value is a number, you can also remove the double quotes (so the API payload becomes -d '{"value":NUMBER}' ). Please, keep me update if this command works or not.

Another cracking reply. It has worked a treat again, thank you very much for your help. Yes I was just trying to change a property's value, and this was the correct way of doing it.