0

REST API previous and next
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

REST API previous and next

by koaiwi on Wed Jan 03, 2018 4:55 am

Hi

can anyone tell me what the next and previous data in queue is meant to do. I get last but the docs do not really explain next and previous.

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

Re: REST API previous and next

by abachman on Wed Jan 03, 2018 6:34 pm

Hi koaiwi!


Sorry about that, I've added a sentence or two of detail to the data queue processing methods at https://io.adafruit.com/api/docs

The /next and /prev HTTP requests walk through the list of all data points in a feed chronologically. Requesting /{username}/feeds/{feed_key}/data/next for a feed you haven't pulled from before gets the first data point in the feed. Subsequent requests to /next walk forward in time. Requests to /previous get the most recently retrieved data point. /first and /last get the oldest and newest data points, respectively, and also reset the queue processing pointer to the first or last point. Calling /next when you're already on the last data point will give an HTTP 404 (Not Found) status code.

The intent is to provide a controllable way of ingesting feed data without missing any data points. MQTT subscriptions are reliable and can let you receive everything, but a low power device (small memory capacity, limited processing speed) may still miss messages based on transient network conditions or the limits of the device. With that in mind, we built the first/next/previous/last API endpoints to enable on-demand streaming of data.

As an example, if you had a low-powered device you could have it wake up once every five minutes and request /{username}/feeds/{feed_key}/data/next to get any data points that were created since the last request. If data is returned, deal with it and call /next again until you get a 404.

Hopefully that's enough to get you started. Please let us know if there's something obvious here that would be helpful and we're missing.


- Adam

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

Re: REST API previous and next

by koaiwi on Thu Jan 04, 2018 5:25 pm

Thanks Adam. I'll give it a try. Am I right in thinking that the server keeps a pointer so the next/[previous just moves from that pointer? I'm using various ESP's.

Any thoughts on my post viewtopic.php?f=56&t=128850 about reducing tha amout of data coming back when requesting data points between 2 datses?

Thanks.

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

Re: REST API previous and next

by abachman on Thu Jan 04, 2018 6:40 pm

Am I right in thinking that the server keeps a pointer so the next/[previous just moves from that pointer?


Yes, that's accurate. The ID of the last data point returned is stored with the feed record, so it's effectively global. Two devices both calling /next alternately will get different streams because each call pushes the pointer forwards. It's simplistic, but functional as a simple queue. If you wanted to implement a more robust solution, you could use a combination of the GET /data API, and the start_time and limit params, plugging in the last created_at value you retrieved and 1, respectively. That should always return the next newest data point after the given start_time value.

Any thoughts on my post viewtopic.php?f=56&t=128850 about reducing tha amout of data coming back when requesting data points between 2 datses?


Also, to the data reduction question, the data GET APIs support a filtering param ("include") that accepts one or more of: value, lat, lon, ele, id, and created_at, separated by commas. For example ".../data?include=value,created_at". It just wasn't documented until now, thanks for the nudge to get that up. I'll post a pointer to this thread under your other post.

So, using curl, you could do something like this to get the 10 most recent values with their created_at timestamps:
Code: Select all | TOGGLE FULL SIZE
curl -H "X-AIO-Key: $IO_KEY" "https://io.adafruit.com/api/v2/$IO_USER/feeds/$FEED_KEY/data.csv?limit=10&include=created_at,value"

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

Re: REST API previous and next

by koaiwi on Thu Jan 04, 2018 7:11 pm

Brilliant.

I get the feeling there is some good stuff in there. The documentation just needs to catch up. Like some curl eg's for each API call in the API docs. I think a lot of the more techie programmers can understand that easily and adapt to the platform they are using. The Arduino library is fine but I can't really understand what it is doing so the API is my preferred method.

Anyway after some playing around on yun and esp I think I can do what I need now.

Thanks.

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

Re: REST API previous and next

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

So, using curl, you could do something like this to get the 10 most recent values with their created_at timestamps:
Code: Select all | TOGGLE FULL SIZE
curl -H "X-AIO-Key: $IO_KEY" "https://io.adafruit.com/api/v2/$IO_USER/feeds/$FEED_KEY/data.csv?limit=10&include=created_at,value"


How can anybody work out any of this from the docs? The docs only refer to
"get /{username}/feeds/{feed_key}/data". How would we ever know that a "get /{username}/feeds/{feed_key}/data.csv" URL also exists?

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

Please be positive and constructive with your questions and comments.