Apologies in advanced, n00b question.
I’m trying to do a simple proof-of-concept to post data from an Raspberry Pi (using python) using JSON. It is a simple measurement with a timestamp, e.g.:
{"Time": "2018-01-01T15:35:24.491Z","Value": 4.56}
What I can’t work out is how to do API authorisation. I’ve read (and reread) the documentation and trawelled through the forum but can’t see any simple example of how to setup and use the API token.
I can go a remote GET and get the JSON values down I have stored via the simple web-app, e.g.
curl -i -X GET https://<my-app-name>.bubbleapps.io/version-test/api/1.1/obj/Measurement/
but doing a POST, e.g.:
curl -i -XPOST -H 'Content-Type: application/json' -d '{"Time": "2018-01-01T15:35:24.491Z","Value": 4.56}' https://<my-app-name>.bubbleapps.io/version-test/api/1.1/obj/Measurement/
I get the 401 error code as expected.
I’m sure it’s pretty straight forward but I’m just completely perplexed?
Any/All help most welcome
Okay…
So what you need to do is add the Authorization token in the header.
You can find the token in your Bubble Editor.
After that add the token to your curl command as a header…
curl -i -XPOST --header “Authorization: KEY”
-H ‘Content-Type: application/json’ -d ‘{“Time”: “2018-01-01T15:35:24.491Z”,“Value”: 4.56}’ https://.bubbleapps.io/version-test/api/1.1/obj/Measurement/
Check out Postman…its much simpler to test and debug your API’s using Postman rather than using curl
Thanks for the quick response. I’d already created an API token and was trying the
?<api_token_name>=key_value" combination
Where you have “Authorization: KEY” in the editor what should I put there?
I’ve tried the key and key_name=key_value and neither seem to get the response.
I’ll check up Postman as well, thanks for the recommendation
You need to add the API token as a header.
i.e
–header “Authorization: KEY”
Currently you are passing it as a parameter
Sorry, Yes I understand that and I’ve tried that but without success.
Postman seems be a better route so I’ll perceiver with that.
Thanks again for the help.
Just for reference I needed:
curl -i -X POST --header "Authorization: Bearer <api key value>"
to get it working via curl, but Postman is much nicer.
Cheers.