eventespresso / event-espresso-core

Event Espresso 4 Core for WordPress: Build an Event Ticketing Website Today!
https://eventespresso.com
GNU General Public License v3.0
121 stars 87 forks source link

Query events via REST doesn't seem to allow filtering by date #162

Closed sgodkin closed 8 years ago

sgodkin commented 8 years ago

I'm trying to query events after a particular date. I'm using Chrome Postman for a proof of concept and can filter by other columns, but filtering by event start date seems to always return everything. As a side note, the documentation references a section that lists entities but I can't find it. My goal is to find all the events after a start date sorted in order of start date.

As suggested in an earlier email the url I'm calling is:

.../events?include=Datetime.*&where[Event.DTT_EVT_start][]=>&where[Event.DTT_EVT_Start][]=2017-05-15T00:00:00

It's returning events that started prior to 2017. This is likely a syntax issue but I'm getting nowhere. Help!

mnelson4 commented 8 years ago

Here's a query that uses our demo site to find events before August 4th 2016 @ 11 pm. http://demoee.org/demo/wp-json/ee/v4.8.36/events?where[Datetime.DTT_EVT_start][]=<&where[Datetime.DTT_EVT_start][]=2016-08-04T23:00:00&include=Datetime

So you need to switch "Event.DTT_EVT_start" with "Datetime.DTT_EVT_start"; and I think switch ">" for "<" to get events BEFORE the specified date

sgodkin commented 8 years ago

Here is the full url I'm sending using chrome postman. This is a fresh install of wordpress and EE decaf, a sandbox install to play around with. I only have 2 events, one starts 2016-05-14T08:00:00 and the other 2016-06-15T19:00:00. I'm looking to see events starting on May 15th or later so it should return only 1 event but always returns 2. I've tried numerous syntaxes but none seem to do any filtering.

http://www.oassolutions.com/nsn/wp-json/ee/v4.6/events?where[Datetime.DTT_EVT_start][]=>&where[Datetime.DTT_EVT_Start][]=2016-05-15T00:00:00&include=Datetime

mnelson4 commented 8 years ago

aha, you're using the EE4 REST API addon. Ya it didn't handle dates properly. Since we put the EE4 REST API in our main event espresso plugin, that addon has been deprecated.

So I'd suggest

  1. deactivate the EE4 REST API addon, and
  2. deactivate WP API v1 plugin, and
  3. just make sure you're on the latest version of EE4 (I see EE4 decaf is on 4.8.42);

if you're on WP 4.4 or higher, then you can immediately send queries to the EE4 REST API included in EE core. Then you can use the following query: http://www.oassolutions.com/nsn/wp-json/ee/v4.8.36/events?where[Datetime.DTT_EVT_start][]=>&where[Datetime.DTT_EVT_Start][]=2016-05-15T00:00:00&include=Datetime.

Make sense?

sgodkin commented 8 years ago

Awesome, that was the issue.

I'm missing a fundamental piece of the puzzle around JSON querying. The JSON response returns the value "datetimes", but when I'm querying I can't use "datetimes" in the where condition but need to use "Datetime". The only reason I know to use Datetime is because I've seen examples online. Is there a document somewhere that explains this and any related info? Thanks for your help.

e.g. [ { ... "_calculated_fields": {}, "datetimes": [ <=================== { "DTT_ID": 1, "DTT_name": "", ...

mnelson4 commented 8 years ago

yeah here's the documentation: https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API

mnelson4 commented 8 years ago

specifically https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-GET-filtering-results.md is probably the most helpful. Basically, in the querystring always use capitalized the related model names; but in the url or response entities, use lowercase and pluralize when there could be more than one item in the collection