• Pages
  • /
  • Dealers
  • /
  • Data Depot
  • /
  • Version 4
  • /
  • API
  • /
  • Helpers
  • /
  • Counts

Counts

All the ways to get total record counts of various data.

There are a few ways to get counts. The two primary methods are:

  1. ?countOnly=true
  2. ?include={entity}:count

These count helpers can be used on any endpoint and in combination with filters and other helpers too.

Example requests

countOnly=true

Let's start with a simple one: Warehouses. Get a total count of all Warehouses.

https://api.wps-inc.com/warehouses?countOnly=true

Easy, right? WPS has six warehouses so this request returns 6 in the structured JSON response.

Next, why not try a more useful endpoint like getting a total count of all Items?

https://api.wps-inc.com/items?countOnly=true

But what about relations?

Let's try getting all the Items for a Product.

https://api.wps-inc.com/products/212415/items?countOnly=true

Perhaps you want to combine this functionality with other helper parameters (like Filters) to produce even more powerful queries. Piece of cake!

Get a count of all FLY Racing branded Items.

https://api.wps-inc.com/items?filter[brand_id]=135&countOnly=true

include={entity}:counts

Let's say we want quickly see how many Items are attached to Product.

Get a total count of all Items in the collection of Product.

https://api.wps-inc.com/products?include=items:count

Get a total count of Items for a specific Product.

https://api.wps-inc.com/products/212415?include=items:count

Ready for a more complicated one? This is how you would count includes that are filtered. Read more about Filtering Includes. This example request will include the Items count, but filtered by only those Items that have a list_price less than $112.96 for a specific Product.

https://api.wps-inc.com/products/211890?include=items:filter(list_price|112.96|lt)count