Yes. here is the code:
curl --request GET \
--url https://api2.arduino.cc/iot/v2/things/6e171f42-ed71-44a8-8425-0bff2724855d/properties \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2FwaTIuYXJkdWluby5jYy9pb3QiLCJhenAiOiI2TjBoeUZoRnRESTBONlI1Z0JOYUdXZkNocm83N1ZmNSIsImV4cCI6MTcyMDEzODU1NywiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiaHR0cDovL2FyZHVpbm8uY2MvY2xpZW50X2lkIjoiRm9yX1B5dGhvbiIsImh0dHA6Ly9hcmR1aW5vLmNjL2lkIjoiNjUzNzcxZDctZDNhMS00M2E1LWJhNDEtMjc3YmMwZTBhZWQ0IiwiaHR0cDovL2FyZHVpbm8uY2MvcmF0ZWxpbWl0IjoxMCwiaHR0cDovL2FyZHVpbm8uY2MvdXNlcm5hbWUiOiJmemVocmExIiwiaWF0IjoxNzIwMTM4MjU3LCJzdWIiOiI2TjBoeUZoRnRESTBONlI1Z0JOYUdXZkNocm83N1ZmNUBjbGllbnRzIn0.yNnzO4oISQhIJ7GXTFWu64OZ5z8MAGT50rmvHkRmcIg'
I still get errors.
I tried it in Python though, and when i get token and list things of the specific space, it gives me the results:
import iot_api_client as iot
from iot_api_client.rest import ApiException
from iot_api_client.configuration import Configuration
# Configure the API client
client_config = Configuration(host="https://api2.arduino.cc/iot")
client_config.access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2FwaTIuYXJkdWluby5jYy9pb3QiLCJhenAiOiI2TjBoeUZoRnRESTBONlI1Z0JOYUdXZkNocm83N1ZmNSIsImV4cCI6MTcyMDEzNzUwOCwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiaHR0cDovL2FyZHVpbm8uY2MvY2xpZW50X2lkIjoiRm9yX1B5dGhvbiIsImh0dHA6Ly9hcmR1aW5vLmNjL2lkIjoiNjUzNzcxZDctZDNhMS00M2E1LWJhNDEtMjc3YmMwZTBhZWQ0IiwiaHR0cDovL2FyZHVpbm8uY2MvcmF0ZWxpbWl0IjoxMCwiaHR0cDovL2FyZHVpbm8uY2MvdXNlcm5hbWUiOiJmemVocmExIiwiaWF0IjoxNzIwMTM3MjA4LCJzdWIiOiI2TjBoeUZoRnRESTBONlI1Z0JOYUdXZkNocm83N1ZmNUBjbGllbnRzIn0.Xr_-VfAULkU1YwZ9JWj5h7Avp4n7ynzTTCkQMGy0aKA'
# Create an instance of the API client
client = iot.ApiClient(client_config)
# Set the organization ID as a header
org_id = "orgID"
client.set_default_header("X-Organization", org_id)
# As an example, interact with the devices API
devices_api = iot.DevicesV2Api(client)
try:
devices_list = devices_api.devices_v2_list()
# Assuming devices_list is a list of devices
for device in devices_list:
print(f"Device ({device.id}): {device.name}") # Adjust property names accordingly
except ApiException as e:
print(f"Exception when calling DevicesV2Api: {e}")
but when i try to get properties of things with the code in python below, it gives me errors.
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
import iot_api_client as iot
from iot_api_client.rest import ApiException
from iot_api_client.configuration import Configuration
import iot_api_client.apis.tags.things_v2_api as thingApi
import iot_api_client.apis.tags.properties_v2_api as propertiesApi
import iot_api_client.apis.tags.series_v2_api as seriesApi
import csv
from time import sleep
HOST = "https://api2.arduino.cc/iot"
TOKEN_URL = "https://api2.arduino.cc/iot/v1/clients/token"
client_id="ID" # get a valid one from your Arduino account
client_secret="secret" # get a valid one from your Arduino account
org_id="orgID"
extract_from="2024-06-03T00:00:00Z"
extract_to="2024-06-06T00:00:00Z"
filename="dump.csv"
def get_token():
oauth_client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=oauth_client)
token = oauth.fetch_token(
token_url=TOKEN_URL,
client_id=client_id,
client_secret=client_secret,
include_client_id=True,
audience=HOST,
headers={"X-Organization":org_id}
)
return token
def init_client(token):
client_config = Configuration(HOST)
client_config.access_token = token.get("access_token")
if org_id!="":
client = iot.ApiClient(client_config,header_name="X-Organization",header_value=org_id)
else :
client = iot.ApiClient(client_config)
return client
def dump_property_data(series_api,thing_name,prop_name,thing_id,prop_id):
sleep(1)
print(f"Extracting property {thing_name}.{prop_name}")
body={
'resp_version':1,
'requests': [ {'q': "property."+prop_id,'from':extract_from,'to':extract_to} ]
}
timeseries=series_api.series_v2_batch_query_raw(body)
if timeseries.response.status==200:
data = timeseries.body['responses']
for s in data:
times = s['times']
values = s['values']
i=0
while i<len(times):
writer.writerow([thing_name,prop_name,times[i],values[i]])
i=i+1
else:print(f"Unable to extract data for property {prop_id}")
def get_things_and_props():
token = get_token()
client = init_client(token)
things_api = thingApi.ThingsV2Api(client)
properties_api = propertiesApi.PropertiesV2Api(client)
series_api = seriesApi.SeriesV2Api(client)
todolist=[] #use this to track extractions to do
try:
things = things_api.things_v2_list()
if things.response.status==200:
for thing in things.body:
sleep(5)
tname=thing["name"]
print(f"Found thing: {tname}")
todo={}
todo["thing_id"]=thing["id"]
todo["thing_name"]=tname
properties=properties_api.properties_v2_list(path_params={'id': thing["id"]})
for property in properties.body:
id = property["id"]
name = property["name"]
ptype = property["type"]
value = property["last_value"]
print(f"Property: {name}::{ptype}={value}")
if ptype=="FLOAT" or ptype=="INT":
todo["prop_id"]=id
todo["prop_name"]=name
todolist.append(todo.copy())
else:
print("IoT API returned status "+things.response.status)
except ApiException as e:
print("Exception: {}".format(e))
while len(todolist)!=0:
todo = todolist.pop()
try:
dump_property_data(series_api,todo["thing_name"],todo["prop_name"],todo["thing_id"],todo["prop_id"])
except ApiException as e:
print("Exception: {}".format(e))
#################
with open(filename, 'w', newline='') as outfile:
writer = csv.writer(outfile)
writer.writerow(["thing_name","variable","timestamp","value"])
get_things_and_props()
errors:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[6], line 7
5 from iot_api_client.rest import ApiException
6 from iot_api_client.configuration import Configuration
----> 7 import iot_api_client.apis.tags.things_v2_api as thingApi
8 import iot_api_client.apis.tags.properties_v2_api as propertiesApi
9 import iot_api_client.apis.tags.series_v2_api as seriesApi
File c:\Users\fzehra1\AppData\Local\anaconda3\Lib\site-packages\iot_api_client\apis\tags\things_v2_api.py:12
1 # coding: utf-8
3 """
4 Arduino IoT Cloud API
5
(...)
9 Generated by: https://openapi-generator.tech
10 """
---> 12 from iot_api_client.paths.v2_things_id_clone.put import ThingsV2Clone
13 from iot_api_client.paths.v2_things.put import ThingsV2Create
14 from iot_api_client.paths.v2_things_id_sketch.put import ThingsV2CreateSketch
File c:\Users\fzehra1\AppData\Local\anaconda3\Lib\site-packages\iot_api_client\paths\v2_things_id_clone\put.py:54
50 class RequestHeaderParams(RequestRequiredHeaderParams, RequestOptionalHeaderParams):
51 pass
---> 54 request_header_x_organization = api_client.HeaderParameter(
...
58 )
59 # Path params
60 IdSchema = schemas.StrSchema
AttributeError: module 'iot_api_client.api_client' has no attribute 'HeaderParameter'
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
Im using arduino-iot-client version 1.4.4 for displaying list of things, but its not working to display properties. I tried with latest version as well 2.0.1. but it doesn't work