Comment on page
Count
Returns a count of the number of items available.
In the following example, we will use Addons to return a count of items. It will use the same example data from List of items and Single items. The example will use an Addon to extend the merchant records with a count of the deals available with each record.
First, within the Query all Records function we will create and Addon. Then, we will choose the deal table to add to the response.
.png?alt=media&token=2313552b-0f31-4f53-aab9-6d5fd76b7bce)
In this example, we will add the deal table to our response of the merchant records.
Next, we will choose how we want the data returned. For this example, we will return the data by item count.
.png?alt=media&token=f851fc86-6684-4199-97c3-e0f914097833)
In this example, we are returning the Addon data with an item count.
Then, we choose the field in the deal database table to map to the merchant table.
.png?alt=media&token=b8da4323-2860-47b4-af60-63ff1f7e947a)
In this example, we are using the merchant_id in the deal table to map to the merchant database table.
The last steps are to give the Addon a name, confirm the mapped field and optionally customize the response. However, since this Addon is returning a count, we actually don't have anything to optionally customize for the Addon response.
Once those steps are complete, we will see a preview of how the response of the Query all Records for the merchant table will be extended.
.png?alt=media&token=ebf691b0-79d0-45d8-947e-566456406601)
In this example, we can see the response is being extended by the Addon deal_of_merchant. It will return a count of deals available for each merchant.
Finally, once we run this API endpoint, we can see the Addon is returning a count of deals associated with the merchant record.
.png?alt=media&token=c7d2b043-2c54-463e-8ade-0390a388c7b1)
In this example, the Addon is returning a count of 3. Meaning there are 3 deals available for the merchant Zuni Cafe.
Last modified 2yr ago