Help with the API – Flair
- 5 years ago
Hi,
I'm trying to change few things by using the API, I can connect, authenticate, get the details of the structures but I have problems in updating the structure attributes, the provided example in the doc doesn't work :
import requests
url = "https://api.flair.co/api/structures/4351"
payload = "{"data":{"type":"structures","attributes":{"active-schedule-id":"e569ca11-643d-499d-8090-c3e4902d1cb9"}}}"
headers= {}
response = requests.request("PATCH", url, headers=headers, data = payload)
I changed the structure Id to my own structure id and I tried to update the 'set-point-temperature-c' but no luck. (Also it's missing the headers for the authentication)
Every time I'm getting the following error: '{"errors": [{"title": "Bad Request", "status": "400", "detail": ["This request could not be processed."]}]}'
Here is my own code:
_url = " [https://api.flair.co/api/structures/](https://api.flair.co/api/structures/)"
+ id_
_payload = "{\"data\":{\"type\":\"structures\",\"attributes\":{\"set-point-temperature-c\":25.00}}}"_
_headers = { 'Content-Type': 'application/x-www-form-urlencoded','Accept': 'application/json','Authorization': 'Bearer ' + access_token }_
_response = requests.patch(url, headers=headers, params=payload)_
_print(response.text.encode('utf8'))_
id contains my structure id and access_token my authentication token.
Any help would be appreciated :)
### Comments
1 comment
Sort by Date Votes
-
[Jerome Morignot](https://support.flair.co/hc/en-us/profiles/401148027312-Jerome-Morignot)
- 5 years ago
I actually solved my problem...it works now. The trick was in the header only '_Authorization': 'Bearer ' + access_token_ is needed _...._ Using the provided example and the proper header I can update attributes as I see fit now. Coooool ;) Pun intended.