Filtering

When accessing data via the API, there are three types of relationships that are exposed. They are described below.

Relationship TypeSample AttributeSample Value

Simple Attribute

orders.total

Total value of the order

One-To-One

orders.shipping_address

A single address entity or null if one isn't set.

One-To-Many

order.line_items

An array of line_item entities. If there are no line_items associated with this order, the array is empty.

Simple Filtering

The Rest API currently only supports simple filtering, while our "Server Side API" or "Entity Access" which can be accessed on the server side supports both simple and advanced filtering.

Simple filtering allows the API caller to filter results by attributes that can be combined with the and logical operator. That format looks like:

<attributes>:<operator>:<value>,..

Example: Let's say you have a product that has some product variants. On the product variants table there is a column called visible and we want to filter all of theproduct variants that are visible that have a price over $80

$ curl -s -G '<base-url>/wp-json/nc-data/v1/product-variants' -d filter='product_variants.visible:eq:1,price:gt:80'   | jq .data

In order to get all the product variants we filter product_variants.visible attribute eq (equal) to 1 since that column is a boolean and which is specified by the comma price is greather than 80.

Supported Operators

The follow operators for filtering are supported.

  • eq - equals

  • equal - equals

  • lt - less than

  • gt - greater than

  • like - SQL LIKE operator using % as the wildcard

  • neq - Not equal to

If you aren't familar with the SQL LIKE operator then using that filter will give you all the data that contains the filtered value. For example:

/wp-json/nc-data/v1/products?filter=name:like:%bracelet%

and in the above example I would return all the products that name contain the word bracelet

Last updated