Hi there Apilio community,
I’m quite new to using Apilio but have found it very useful in my home automation journey. My original plan was to pair up Apilio and IFTTT (as a lot of people seem to do) but am finding things get quite complex quite quickly. I have now decided to run custom (python) programs on Raspberry Pi with calls to read inputs (control actions) from Apilio variables, and write outputs to Apilio variables (the results of the control actions). The design principal being I only want outbound traffic from my home (no open ports). Things are going well.
I’m hitting a snag with updating Apilio variable using PUT request. I consistently get status code 500 with this returned: {“error”:“param is missing or the value is empty: boolean_variable\nDid you mean? {“boolean_variable”: {“value”:false}}\n controller\n action\n uuid”}
Thanks James, @pebneter (the ) is probably best place to help with this question. Love the architecture, sounds exciting and would be great if you could share a little more at some stage!
But PUT requests aren’t:
curl -u username:password --location --request PUT ‘https://api.apilio.com/api/v1/boolean_variables/uuid’ --header ‘Accept: application/json’ --data-raw ‘{“boolean_variable”: {“value”: false}}’
(where username, password and uuid are variables)
Doesn’t seem to matter whether I use my python script, postman or curl I seem to get consistent 200 response for GET, and consistent 500 response for PUT.
Oh, BTW, I know I can update variables using web hooks but use wanted to use REST API for everything to keep it clean but will use web hooks for updates if need be.
Hi James,
I did a quick analysis to reproduce your problem.
I was able to do so and adding a header "–header ‘Content-Type: application/json’ " helped.
Can you try it?
In any case, we will investigate further and either fix the bug or adapt the documentation.
You are spot on. The GET requests don’t require the "–header ‘Content-Type: application/json’ " BUT the PUT requests do. I have verified adding this to the header makes the PUT request work within postman, curl and my custom python program.
So for completeness for the Apilio Community this works:
Also, a bug(?) report…the successful PUT request doesn’t seem to log an event like I’d expect it to. Updating values via the Apilio Web UI does create a log record, whereas the REST PUT doesn’t. Doesn’t bother me as I’m not after that level of auditing but it looks like an omission.
The GET requests don’t require the "–header ‘Content-Type: application/json’ " BUT the PUT requests do.
This is expected as the GET request doesn’t have a payload, whereas the PUT request does. So looks like not a bug at all but the doco needs to be updated.
Hi @James ,
we are going to deploy a fix soon that changes the requirements for the requests:
Accept header is no longer necessary (as for now, the API will always return JSON)
The Content-Type header is required (and will be documented) for all requests except GET. If we can’t find it in the request, the system will respond with a more helpful error message.
I think you don’t need to update your script immediately as the supplied accept header should not cause an issue.