0

curl simple usage
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

curl simple usage

by ds18s20 on Sat Oct 24, 2015 11:22 am

I read about the library and the other methods but I couldn't find a simple curl example, is it not possible or this is so simple one is supposed to figure it out on their own (I am clearly outside of that group...lol)

Thanks everyone
~B

ds18s20
 
Posts: 38
Joined: Tue Jan 24, 2012 7:45 pm

Re: curl simple usage

by awall on Sun Oct 25, 2015 4:01 am

I was also surprised to see that in the REST API tutorial there was no CURL example, as it is a very common way to use or just test http based APIs.
But I'am also quite savvy with CURL so I created the scripts my own and was already planning to offer a short tutorial to match the API reference.

[BTW: if the moderators are interested in that, just let me know what's the best way to do that].

Here's an example on how to publish a value in a feed. Replace the placeholders with your AIO key and feed name/number:

Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -X PUT -d "{\"last_value\":\"abc123\"}" -H "x-aio-key: ...your_AIO_key..." http://io.adafruit.com/api/feeds/<your_feed_name>.json

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

Re: curl simple usage

by jmpantelis on Sun Oct 25, 2015 6:53 am


jmpantelis
 
Posts: 11
Joined: Fri Mar 20, 2015 2:15 pm

Re: curl simple usage

by awall on Sun Oct 25, 2015 8:07 am

No doubt this tool is interesting, but the original question was on how to use CURL as nobody posted an example before.

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

Re: curl simple usage

by ds18s20 on Sun Oct 25, 2015 10:37 am

Thanks @awall that's exactly what I was looking for!

ds18s20
 
Posts: 38
Joined: Tue Jan 24, 2012 7:45 pm

Re: curl simple usage

by awall on Sun Oct 25, 2015 6:19 pm

Glad it helped

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

Re: curl simple usage

by jwcooper on Wed Nov 04, 2015 12:14 am

Good points on this not being in our docs. I'll make a note to get curl examples added.

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

Re: curl simple usage

by richarduk on Sat Nov 14, 2015 3:54 pm

Thanks awall, I was banging my head against the wall on this one. I needed the content param to get it working. Not used curl that much before but was the first thing I reached for.

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

Re: curl simple usage

by richarduk on Sat Nov 14, 2015 3:57 pm

jmpantelis wrote:Did you see this tool: https://io.adafruit.com/api/docs/#!/Feeds/all


It is a handy tool but does not show an example for the feed text box. Was not until I read the docs on another page did I realise what was expected in that text box. Most services I have used in the past have an example for each message.

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

Re: curl simple usage

by koaiwi on Thu Dec 28, 2017 7:36 pm

jwcooper wrote:Good points on this not being in our docs. I'll make a note to get curl examples added.

Hi. Any progress on the curl examples. I do concur with the other posts concerning lack of examples. Thanks.

koaiwi
 
Posts: 24
Joined: Thu Dec 28, 2017 10:11 am

Re: curl simple usage

by schellem on Sat Dec 30, 2017 11:15 am

I like the tool but it is of no help on how to make your own calls to the API. I can't seem to find any info on making RAW HTTP requests from say POSTMan.

    How do we authenticate
    What is the full blown Url

The tool need to show the full request.

schellem
 
Posts: 2
Joined: Sat Dec 30, 2017 10:27 am

Re: curl simple usage

by craigio on Fri Jan 12, 2018 7:52 am

As there seems to be no documentation that works, I tried awall's example.
Doing that, I get:
{"error":"Invalid feed parameters provided: last_value. Parameters may include: name, key, description, unit_type, unit_symbol, history, visibility, license, status_notify, status_timeout, enabled"}

craigio
 
Posts: 5
Joined: Fri Jan 12, 2018 7:00 am

Re: curl simple usage

by abachman on Fri Jan 12, 2018 6:42 pm

Hi all,


We're doing our best to keep API documentation up to date, but V2 of our API is a system that's still growing and changing and we're using V2 of the API in building the https://io.adafruit.com user interface so the platform often moves faster than the documentation. We are not trying to hide anything from anyone, there are just things we haven't gotten to yet. :/

Regarding authentication for the API, you'll have to pass in your current API key either as a header, X-AIO-Key: $IO_KEY, or as a URL param, x-aio-key=$IO_KEY. The API will accept either. When reading the documentation, any URL you see at the top of the page--for example, "/{username}/dashboards"--should have the given parameter plugged in in place of the curly brace-surrounded word and should be prefixed by the Base URL shown in the bottom left part of the documentation pages (always "/api/v2"). So to get a list of all your dashboards, you could use the URL: https://io.adafruit.com/api/v2/$IO_USER ... ey=$IO_KEY, where $IO_USERNAME is replaced with your username and $IO_KEY is replaced with your key. As a curl command that would look like:
Code: Select all | TOGGLE FULL SIZE
curl "https://io.adafruit.com/api/v2/$IO_USERNAME/dashboards?x-aio-key=$IO_KEY"


If you prefer to send the key as a header, that would be
Code: Select all | TOGGLE FULL SIZE
curl -H "X-AIO-Key: $IO_KEY" "https://io.adafruit.com/api/v2/$IO_USERNAME/dashboards"


If you find that the documentation is particularly confusing or inadequate in describing how to use the endpoints, you might have better luck navigating the API by taking a look at one of our open source API clients (Javascript, Python, Ruby, Arduino) for examples of the API in action. In particular, the Arduino client and the beta release of the Ruby client use V2 which is where development is actively happening.

Additionally, every piece of data you see on https://io.adafruit.com is pulled from https://io.adafruit.com/api/v2. Keeping your browser's web inspector open on the network tab while you're browsing around will give you a rough idea of how we're using it.

Regarding curl, while we will eventually provide some "official" examples of curl usage and we may use it in the forums for demonstration purposes, the full scope of that tool is still going to be best explored via its official documentation.


- adam

abachman
 
Posts: 185
Joined: Mon Feb 01, 2010 12:48 pm

Re: curl simple usage

by craigio on Fri Jan 12, 2018 9:27 pm

The lack of documentation means there's lots of guesswork for new users.

When I say "new users", I've been using another site for this. Xively (previously Cosm, previously Pachube) is about to close its free accounts. Their API was poorly documented, but this one is worse! I imagine many people coming into this fresh would simply give up, as there are a number of totally non-obvious hurdles to go through to use this API.

1) If you search around on the site, there's a random mix of v1 and v2 API examples, but nothing to say how one maps to the other.
2) Setting x-aio-key is not documented where you'd expect it, in the API reference (https://io.adafruit.com/api/docs/#!/Users/currentUser). There's just a text box for it which doesn't say how to implement it for oneself! It's necessary to do searches through this forum to find the most basic requirement of using the API.
3) Setting "Content-Type: application/json" is required but non-obvious. The previous site I was using didn't require this.
4) Whether to use GET, PUT or POST for any particular URL isn't documented!
5) Whole classes of URLs aren't documented. (Adam's mentioned ones ending in .csv I think, but there's nothing about those in the API reference.)

I finally found a code example that works for uploading data, and it's one of Adam's in another thread:
Code: Select all | TOGGLE FULL SIZE
curl -H "Content-Type: application/json" -d '{"value": 23, "lat": 39.28327
7, "lon": "-76.611818", "ele": "10"}'  -H "X-AIO-Key: $AIO_KEY" https://io.adafr
uit.com/api/v2/test_man/feeds/mapcoodenadas/data

craigio
 
Posts: 5
Joined: Fri Jan 12, 2018 7:00 am

Re: curl simple usage

by koaiwi on Sat Jan 13, 2018 12:47 am

Yes it is certainly work in progress but I think what I have so far is looking good. I've completely swapped out from xively (just in time) with over 100 feeds across 10 devices (Yun and wemos).

All seems to be working well. I like the dashboards and web user interface.

The price is right and at lease there is support. Logmein completely destroyed pachube. Shame on them. They took an open source product created by a community, changed it into something very unusable and now charge $1000s.

I trust you guys will eventually get the docs up to date. If we point out something missing then the gap appears to be filled. The forum will help.

So far I have found everything I need and more to replace xively.

koaiwi
 
Posts: 24
Joined: Thu Dec 28, 2017 10:11 am

Please be positive and constructive with your questions and comments.