The aggregate node lets you organize and calculate data easily. You can group a list of items by a field (like “category”) and perform operations like:
- Totaling numeric values (sum)
- Averaging values
- Counting how many items exist in each group
This node is perfect for reports, dashboards, or anytime you need quick summaries from your data.
Endpoint Information
- Method: POST
- URL:
https://node.nodetrigger.com/api/aggregate
- Content-Type:
application/json
Request Format
Send a request with three main parts:
Field | Type | Required | Description |
---|---|---|---|
array | List | Yes | The list of items you want to group and analyze. Each item must be an object with the fields you’re using. |
groupBy | String | Yes | The name of the field to group the data by. This field must exist in each item. |
operations | Object | Yes | Define which calculations you want to perform. See below for details. You can include just one operation or combine all three. |
Operations You Can Use
The operations
object can include one or more of the following:
1. count
Counts how many items are in each group.
"count": true
This will add a field like "count": 3
in each result.
2. sum
Calculates the total (sum) of one or more numeric fields in each group.
"sum": ["price", "tax"]
This will return fields like:
"sum_price": 50,
"sum_tax": 4.5
Make sure the fields you include are numeric (e.g. price, quantity, amount).
3. average
Calculates the average of one or more numeric fields.
"average": ["discount"]
This will return:
"avg_discount": 3.75
Only valid numbers are used in the calculation. If there are no valid numbers, the average will be null
.
Complete Example
Request:
{
"array": [
{ "category": "Books", "price": 10, "discount": 2 },
{ "category": "Books", "price": 20, "discount": 4 },
{ "category": "Toys", "price": 15, "discount": 3 }
],
"groupBy": "category",
"operations": {
"count": true,
"sum": ["price"],
"average": ["discount"]
}
}
Response:
[
{
"category": "Books",
"count": 2,
"sum_price": 30,
"avg_discount": 3.00
},
{
"category": "Toys",
"count": 1,
"sum_price": 15,
"avg_discount": 3.00
}
]
Notes
- You can include just one operation or combine all three.
groupBy
must match a field name that exists in each object.- Non-numeric values in
sum
oraverage
fields will be ignored automatically. - If a field is missing from an item, it’s treated as zero (for sum) or skipped (for average).
Use Cases
- Group sales by product and calculate total revenue
- Count support tickets by priority
- Average ratings per category
- Sum hours logged by each employee