I’m trying my best to convert the curl command to an http get command. I keep getting a 401 response back from the call. If I run the curl command eveyrhting works was expected.
I’m writing an API integration for Adafruit’s Circuit Python on an ESP32-S3 microcontroller. I wish there was more REST documentation for pure GET’s instead of just CURL. I figured it out in about an hour because I have a lot of experience working with all sorts of API’s from YouTube and Github to Fitbit and Mastodon. The actual integration was easy for me but the documentation is severely lacking compared to most other API’s especially for REST GET requests.
First you have to do a get for the person id with the correct API Key. That will respond with a very long unique PersonID though it might as well be considered a token because it looks like a hashed token format. You then do a 2nd call using the person id.
For a python get request it would look something like
RACHIO_KEY = "Your API Key Here"
RACHIO_HEADER = {"Authorization": " Bearer " + RACHIO_KEY}
RACHIO_SOURCE = "https://api.rach.io/1/public/person/info/"
RACHIO_PERSON_SOURCE = "https://api.rach.io/1/public/person/"
try:
with requests.get(url=RACHIO_SOURCE, headers=RACHIO_HEADER) as rachio_response:
rachio_json = rachio_response.json()
except ConnectionError as e:
print("Connection Error:", e)
# This will return your unique PersonID.
rachio_id = rachio_json["id"]
# Then you make a 2nd request using the personid (rachio_id) authorized from the first request.
# Now you can pull any data outlined in the API documentation.
try:
with requests.get(url=RACHIO_PERSON_SOURCE +rachio_id, headers=RACHIO_HEADER) as rachio_response:
rachio_json = rachio_response.json()
except ConnectionError as e:
print("Connection Error:", e)
rachio_id = rachio_json["id"]
print(" | | UserID: ", rachio_id)
rachio_username = rachio_json["username"]
print(" | | Username: ", rachio_username)
rachio_devices = rachio_json["devices"][0]["name"]
print(" | | Devices: ", rachio_devices)
rachio_model = rachio_json["devices"][0]["model"]
print(" | | | Model: ", rachio_model)
# and so on...
I am using a fork of Micropython but most GET requests for REST API’s are easily adaptable to other REST API frameworks.