Jump to content

webservice api filter for date ranges


alexdoan101

Recommended Posts

HI,

does anyone know how to do filter for date ranges for the webservice orders api?

You can do this for an exact timestamp

api/orders?filter[invoice_date]=[2011-03-31 08:59:13]

but i want to search on date range. How do i filter for a date range?

Link to comment
Share on other sites

  • 8 months later...

Hey Alex,

 

Don't know if you still need this, but I have it for you.

 

Here's how to filter between a range of dates: api/orders?filter[invoice_date]=[2011-03-3,2011-3-4]&date=1

 

You have to put that silly "date=1" in the params otherwise it no worky. A bug out there and this was the patch apparently. This applies for using CURL against the API as well.

 

Hope this helps!

  • Like 1
Link to comment
Share on other sites

  • 5 years later...
  • 1 month later...

Hi,

 

I need to integrate my prestashop with multiple warehouse management systems. Each product is however unique to a warehouse and can be defined by the supplier or warehouse fields. The warehouse system api however calls for all orders from prestashop, but I'd like to only send orders for products specific to that supplier or warehouse through the api call although the warehouse system is calling for all orders. Is it possible to achieve this in an easy way without a code change at the warehouse api end (since that is a 3rd party tool). Maybe by adding filters to the incoming api call and passing it on?

Link to comment
Share on other sites

  • 6 years later...

Wanted to restrict the selection of orders by Invoice_date but the following command has no effect, all orders come. With this selection, no orders should actually be displayed in my case. Will be read via webservice-

orders/?filter[invoice_date]=[2023-07-25 10:56.45,2023-07-26 10:58.43]date=1

Seems like in Prestashop 8.0.4 filtering by a date range doesn't work anymore.

Link to comment
Share on other sites

  • 2 months later...
On 7/27/2023 at 10:45 AM, Frank Begbie said:

Wanted to restrict the selection of orders by Invoice_date but the following command has no effect, all orders come. With this selection, no orders should actually be displayed in my case. Will be read via webservice-

orders/?filter[invoice_date]=[2023-07-25 10:56.45,2023-07-26 10:58.43]date=1

Seems like in Prestashop 8.0.4 filtering by a date range doesn't work anymore.

Hello good sir,

while i'm not on the same version (I am on 1.7.8.3) your problem might be a missing & between the filter and the date parameter.

So your URL should look like this:
orders/?filter[invoice_date]=[2023-07-25 10:56.45,2023-07-26 10:58.43]&date=1

Hope that helps.
 

Link to comment
Share on other sites

In PrestaShop's WebService API, you can filter data based on date ranges using the filter parameter in the URL when making a request to retrieve data. You will typically use the date or date_upd field to filter data based on the creation date or last update date. Here's how you can use the filter parameter to specify date ranges:

Filtering by Creation Date (date_add)

To retrieve data within a specific date range based on the creation date, you can use the filter[date_add] parameter. For example:

CSS

/api/products/?display=full&filter[date_add]=[2023-01-01,2023-12-31]

This example will retrieve products created between January 1, 2023, and December 31, 2023.

Filtering by Update Date (date_upd)

To retrieve data within a specific date range based on the last update date, you can use the filter[date_upd] parameter. For example:

CSS

/api/products/?display=full&filter[date_upd]=[2023-01-01,2023-12-31]

This example will retrieve products that were last updated between January 1, 2023, and December 31, 2023.

Combining Filters

You can also combine multiple filters to specify more complex date ranges or other criteria. For instance, you can filter products that were created within a specific date range and have a certain status:

CSS

/api/products/?display=full&filter[date_add]=[2023-01-01,2023-12-31]&filter[active]=1

This example retrieves active products created between January 1, 2023, and December 31, 2023.

Remember to adapt the endpoint and resource (products in the examples) to your specific use case, as well as the date format to match the format used in your PrestaShop installation.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...