JSON API filter by date

Discussion for TimeTrex open source community developers.
Post Reply
bfang
Posts: 3
Joined: Wed Jul 05, 2017 7:53 am

JSON API filter by date

Post by bfang » Wed Jul 05, 2017 8:01 am

I am attempting to list a series of punches for a given user on a given day using the JSON API, and the "APIPunch" class, "getPunch" method. I am able to filter the results successfully using filter_data;{user_id:'XXXX'}, but all attempts at filtering the results by either "date_stamp" or "punch_date" return all punches, for all days. I have attempted many varieties of date formatting, including a straight Unix timestamp, with no luck. Is there a way to filter punch data by punch date?

shaunw
Posts: 7418
Joined: Tue Sep 19, 2006 2:22 pm

Re: JSON API filter by date

Post by shaunw » Wed Jul 05, 2017 9:04 am

Try adding this to your filter data:

Code: Select all

'start_date': $start_epoch_value, 'end_date': $end_epoch_value

bfang
Posts: 3
Joined: Wed Jul 05, 2017 7:53 am

Re: JSON API filter by date

Post by bfang » Wed Jul 05, 2017 9:16 am

I have added start_date and end_date, and still receive all records. My JSON filter looks like this:

[{"filter_data":{"user_id":"676","start_date":1499212800,"end_date":1499212800}]

When I include the dates, it returns every punch, for every person. If I remove the dates my JSON filter looks like:

[{"filter_data":{"user_id":"676"}]

And this returns only punches for user 676.

shaunw
Posts: 7418
Joined: Tue Sep 19, 2006 2:22 pm

Re: JSON API filter by date

Post by shaunw » Wed Jul 05, 2017 9:26 am

You will need to provide us with more complete code/request samples then, because adding additional parameters shouldn't cause others to be ignored unless there is a bigger problem going on somewhere.

bfang
Posts: 3
Joined: Wed Jul 05, 2017 7:53 am

Re: JSON API filter by date

Post by bfang » Wed Jul 05, 2017 9:44 am

Thank you. I found the issue. I was missing a } at the end of the filter_data json.

Post Reply