question

James Tickett avatar image
James Tickett asked James Tickett commented

Is there a way using API to retrieve only the first order placed?

I'm trying to return only the first order that was made for a particular merchant. I tried:

https://www.eu.clover.com/v3/merchant...

But then realised the sorting is performed on the returned collection, not the whole set of orders that I'm querying.

Is there any way I can request only the first order using the API?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mike M avatar image
Mike M answered James Tickett commented

That's quite interesting. I investigated your issue further, and it seems that adding the limit filter ends up applying your sort only on the returned collection. Removing the limit from the query ends up sorting the whole order set.

orderBy=createdTime%20ASC

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

James Tickett avatar image James Tickett commented ·

Thanks Mike, I've given that a go but it doesn't seem to work the same way for me. When I use orders?orderBy=createdTime%20ASC (no limit specified) it still returns only recent results.

Oddly, if I orderBy=id then I seem to be sorting the entire set of results as the ID's are either starting with 0's or Z's

And if I use a limit of 1, then sorting ascending or descending on createdTime returns a different result, but both from the most recent day rather than back last year!

0 Likes 0 ·
anthonypinto avatar image
anthonypinto answered

Generally the best way to work with the API is to fetch collections by date range, or another relevant filter.

There isn't direct support for querying the first order from the entire history, but you can determine the createdTime of the merchant from the base /v3/merchants/{merchantUUID}/ endpoint. With that timestamp in hand you can filter your query with it:

?filter=createdTime>={merchant.createdTime}
&filter=createdTime<={merchant.createdTime + 1 or 2 months}
&orderBy=createdTime%20ASC&limit=1
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community