question

jeff-davies avatar image
jeff-davies asked jeff-davies commented

Get Orders not filtering properly by date range

Hi all, I'm making a call to get the orders for a single day. In my example, that day is Jan 17. I have been told that the filter query param should be used only once, even when creating complete expressions. As a result, the URL that I am invoking to get orders for Tuesday, Jan 17th is the following:

https://api.clover.com/v3/merchants/{merchant id}/orders?access_token={redacted}&limit=1000&expand=lineItems&filter=clientCreatedTime%3E=1484640000000&clientCreatedTime%3C=1484726399999

The resulting list actually contains all order since the start date. It is as if the clientCreatedTime<= clause is ignored. Has anyone else seen this behavior? Can a Clover dev confirm this, or if my understanding is incorrect, please show me the proper way to create this query?

Thanks in advance!

10 |2000

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

rmgas avatar image
rmgas answered jeff-davies commented

I ran into this too. Very annoying. Two things:

1.) You can use the same filter twice, but you have to have your second date be exclusive. So if you want orders from Jan 30, START needs to be 1/30/17 and END needs to be 1/31/2017 (obviously converting those to millisecs) like this:

...filter=clientCreatedTime>=START&filter=clientCreatedTime<end< p="">

2.) I have learned that I cannot trust the createdTime field when retrieving. I always pull by modifiedTime so that way if something happens like a return, refund, exchange, etc., I'll re-pull the order and all the details of the line items in the event the modified event was on a date later than the purchase. You would still want to use createdTime as your primary index when sorting through orders once you have them downloaded locally. So when pulling, use ModifiedTime; when reviewing once you have the data, use createdTime.

Good luck :)

4 comments
10 |2000

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

jeff-davies avatar image jeff-davies commented ·

Correction to my earlier comment. As it turns out, this is still not working for me. Your first point did not work for me. Clover reported an error parsing the URL, even when I URL encoded the spaces. It seems to need the single ampersand between the two clauses. I tried your 2nd point and I changed the second clause from clientCreatedTime<=END to clientCreatedTime < END. The call does return valid data, but it does not apply the second clause. I do appreciate your time in helping me out. I'll keep tweaking this in hopes of finding the solution.

0 Likes 0 ·
jeff-davies avatar image jeff-davies commented ·

In the mean time, my workaround is to loop over the results in weed out the ones that are past the end date I want. It works OK when getting orders from the past few days, but if I went back a month or so the results would be quite large.

0 Likes 0 ·
rmgas avatar image rmgas commented ·

Another person on here commented with something I missed. You need to use the filter keyword for each one and not an ampersand. I'll correct my original message. Here is the syntax:

https://www.eu.clover.com/v3/merchant... (Credit JTickett)

0 Likes 0 ·
jeff-davies avatar image jeff-davies commented ·

Ok, I'm a dope. When I first tried your suggestion I somehow overlooked adding the 2nd filter query param. One of the devs here mentioned in a post a few weeks ago that using the filter query multiple times did no work. My query DOES now work as mgas suggested. Here is a sample of the URI that is now working for me, just to be clear:

https://api.clover.com:443/v3/merchants/{mid}/orders?access_token={redacted}&limit=1000&expand=lineItems&filter=clientCreatedTime>1485936000000&filter=clientCreatedTime<1486022399999
  • Jeff
0 Likes 0 ·
James Tickett avatar image
James Tickett answered rmgas commented

I think that when you use a range (i.e. using the same filter more than once) you need to express them as a new filter.

Try something like this:

https://www.eu.clover.com/v3/merchants/[MID]/orders?filter=clientCreatedTime<1485763099000&filter=clientCreatedTime>1485533463000
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.

rmgas avatar image rmgas commented ·

You're absolutely correct. Good catch. Was going off of memory.

0 Likes 0 ·

Welcome to the
Clover Developer Community