0

CURL guide for REST API
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

CURL guide for REST API

by awall on Sat Nov 14, 2015 8:07 pm

I've played quite a bit around Adafruit IO REST API using CURL, so I've decided to post a complete guide with examples for all the available API.
All the examples assume the following (brackets must not be included):

- <AIOkey> must be replaced with your own AIO Key;
- <FEEDnum> must be replaced with the feed number (e.g. 1234);
- <FEEDname> must be replaced with the feed name (e.g. MyFeed);
- <DATAid> must be replaced with the ID of the feed data;
- Data in and out is provided in JSON format, but examples can be changed to also support CSV and XML.

List of Feeds
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X GET -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds.json

Create a new Feed
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X POST -d "{\"name\":\"<FEEDname>\"}" -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds.json

Get an existing feed
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X GET -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>.json

Update a feed (send new data)
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X POST -d "{\"value\":\"123\"}" -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data.json

Delete an existing feed
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X DELETE -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>.json

Get all the data in a feed
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X GET -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data.json

Get an existing data object
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X GET -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data/<DATAid>.json

Update an existing data object
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X PUT -d "{\"value\":\"777\"}" -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data/<DATAid>.json
or as an alternative
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X PATCH -d "{\"value\":\"777\"}" -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data/<DATAid>.json

Delete an existing data object
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X DELETE -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data/<DATAid>.json

Send a data object (based on feed name)
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X POST -d "{\"value\":\"456\"}" -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDname>/data/send.json

Get last data object
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X GET -H "x-aio-key: <AIOkey>" http://io.adafruit.com/api/feeds/<FEEDnum>/data/last.json

Optional parameters
- For verbose output use
Code: Select all | TOGGLE FULL SIZE
curl -v

- To invoke commands with SSL use
Code: Select all | TOGGLE FULL SIZE
curl -k using URL https://io.adafruit.com/api/feeds/

Hope this helps out there using REST API.

Regards
Andrea

awall
 
Posts: 24
Joined: Sat Sep 20, 2014 10:40 am

Re: CURL guide for REST API

by richarduk on Sun Nov 15, 2015 3:33 pm

That is great :) I will be referring to your post a lot. Thumbs up. :)

richarduk
 
Posts: 64
Joined: Tue Nov 05, 2013 4:55 pm

Re: CURL guide for REST API

by jwcooper on Mon Nov 16, 2015 1:22 pm

Thanks for posting and sharing this for everyone else to use!

jwcooper
 
Posts: 785
Joined: Tue May 01, 2012 9:08 pm

Please be positive and constructive with your questions and comments.