0

Challenged CURLing reading feeds
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Challenged CURLing reading feeds

by sketchy on Sun Jun 02, 2019 3:30 pm

I don't know what I am doing. I feel the Adafruit.io docs are incomplete. So I need a spot of help.

I want to use curl to get the values between a date range, and for extra credit - limit to 1 record. So that is three things: 1) return values only, 2) between a date range, 3) limit to 1 record.

I can get the values this way:
curl -H "X-AIO-Key: {io_key}" https://io.adafruit.com/api/v2/{username}/feeds/{feed_key}/data?include="value"
I can limit to 1 this way:
curl -H "X-AIO-Key: {io_key}" https://io.adafruit.com/api/v2/{username}/feeds/{feed_key}/data?limit=1

What I don't know how to do:
Correct/acceptable date formats
How to string multiple query parameters together. I tried a variety of things. I apologize for my lack of creativity. With that said, I hope you might consider emboldening the Adafruit.io data/feeds documentation with several examples and/or much more specific input text.

Thank you.

sketchy
 
Posts: 245
Joined: Thu Jun 28, 2012 11:37 pm

Re: Challenged CURLing reading feeds

by abachman on Wed Jun 05, 2019 1:53 pm

hi sketchy!


The most important thing with curl is to put the URL in quotes, especially if you're trying to send multiple parameters.

For example, if you're trying to include=value and limit=1, the URL would be:
Code: Select all | TOGGLE FULL SIZE
https://io.adafruit.com/api/v2/{username}/feeds/{feed_key}/data?include=value&limit=1
bash (if you're on linux or mac) interprets the unquoted `&` symbol as a request to background the command you just entered, which effectively truncates the URL parameters after the first & if the URL isn't in quotes.

As far as date formats, all date parameters should be ISO8601 formatted (YYYY-MM-DDThh:mm:ssZ) UTC date + times. For example, right now it's 2019-06-05T14:25:17Z. If you want to use a timezone instead of UTC, you can replace the "Z" with the timezone offset in "-hh:mm" format. EDT is -04:00, so midnight today in NYC would be "2019-06-05T00:00:00-04:00".

So, if I wanted to get all my temperature values for June 4, I could write the command as:

Code: Select all | TOGGLE FULL SIZE
curl "https://io.adafruit.com/api/v2/abachman/feeds/temperature/data?include=value,created_at&start_time=2019-06-04T00:00Z&end_time=2019-06-05T00:00Z"


The feed is public, so I don't need to include the X-AIO-Key header. If yours isn't, you'll still need it.

NOTE: if there is more data available in the requested date range, the pagination headers will let you know.


- adam b.

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

Re: Challenged CURLing reading feeds

by sketchy on Fri Jun 07, 2019 7:12 pm

HI Adam,
Thanks very much. Your answer was very clear and easy to follow. If it was up to me (and it's not)...you should get one heck-uva-pat-on-the-back and a WELL DONE! In addition, your poetry on curling would find it's way into the adafruit.io to be of aid for the off chance there might be other lost souls on this (or lost soles if we're shoeing it).

sketchy
 
Posts: 245
Joined: Thu Jun 28, 2012 11:37 pm

Please be positive and constructive with your questions and comments.