Examples
How to perform Metrics API queries on the return resource
Breakdown
The following request performs a breakdown query on the return resource:
curl -g -X POST \
'https://{{your_domain}}.commercelayer.io/metrics/returns/breakdown' \
-H 'Accept: application/vnd.api.v1+json' \
-H 'Content-Type: application/vnd.api+json' \
-H 'Authorization: Bearer {{your_access_token}}' \
-d '{
"breakdown": {
"by": "organization.id",
"field": "return.id",
"operator": "value_count",
"sort": "desc",
"limit": 5,
"breakdown": {
"by": "market.id",
"field": "customer.id",
"operator": "value_count",
"sort": "asc",
"limit": 10
}
},
"filter": {
"return": {
"date_from": "2021-05-30T00:00:00Z",
"date_to": "2022-05-30T23:59:00Z",
"date_field": "created_at"
},
"market": {
"names": {
"in": ["USA"]
}
}
}
}'
On success, the API responds with a 200 OK
status code, returning the aggregated values in the data
object and extra information in the meta
object:
{
"data": {
"organization.id": [
{
"label": "mzRmbZFPyO",
"value": 1,
"market.id": [
{
"label": "AjRevhvqvo",
"value": 1
}
]
}
]
},
"meta": {
"type": "breakdown",
"trace_id": "aea0bad6-4032-4f34-a392-5f4bc9f6d55d",
"mode": "test",
"organization_id": "mzRmbZFPyO",
"market_ids": [
"AjRevhvqvo",
"dlQbPhqGro"
]
}
}
Date breakdown
The following request performs a date breakdown query on the return resource:
curl -g -X POST \
'https://{{your_domain}}.commercelayer.io/metrics/returns/date_breakdown' \
-H 'Accept: application/vnd.api.v1+json' \
-H 'Content-Type: application/vnd.api+json' \
-H 'Authorization: Bearer {{your_access_token}}' \
-d '{
"date_breakdown": {
"by": "return.shipped_at",
"field": "return.skus_count",
"interval": "year",
"operator": "stats",
"breakdown": {
"by": "origin_address.country_code",
"field": "origin_address.state_code",
"operator": "value_count",
"sort": "desc",
"limit": 5
}
},
"filter": {
"return": {
"date_from": "2021-01-01T00:00:00Z",
"date_to": "2021-12-30T23:59:00Z"
},
"market": {
"names": {
"in": ["USA"]
}
}
}
}'
On success, the API responds with a 200 OK
status code, returning the aggregated values over the selected time intervals in the data
object and extra information in the meta
object:
{
"data": [
{
"date": "2021-01-01T00:00:00.000Z",
"value": {
"count": 0,
"min": null,
"max": null,
"avg": null,
"sum": 0.0
},
"origin_address.country_code": []
}
],
"meta": {
"type": "date_breakdown",
"trace_id": "05583830-cbcd-448b-9999-86fb1c032ca6",
"mode": "test",
"organization_id": "mzRmbZFPyO",
"market_ids": [
"AjRevhvqvo",
"dlQbPhqGro"
]
}
}
Stats
The following request performs a stats query on the return resource:
curl -g -X POST \
'https://{{your_domain}}.commercelayer.io/metrics/returns/stats' \
-H 'Accept: application/vnd.api.v1+json' \
-H 'Content-Type: application/vnd.api+json' \
-H 'Authorization: Bearer {{your_access_token}}' \
-d '{
"stats": {
"field": "return_line_items.quantity",
"operator": "stats"
},
"filter": {
"return": {
"date_from": "2021-01-01T00:00:00Z",
"date_to": "2021-12-31T23:59:00Z"
},
"market": {
"names": {
"in": ["USA"]
}
}
}
}'
On success, the API responds with a 200 OK
status code, returning the computed value in the data
object and additional information in the meta
object:
{
"data": {
"value": {
"count": 0,
"min": null,
"max": null,
"avg": null,
"sum": 0.0
}
},
"meta": {
"type": "stats",
"trace_id": "89ea9784-890e-4543-85ab-a3bd493be46a",
"mode": "test",
"organization_id": "mzRmbZFPyO",
"market_ids": [
"AjRevhvqvo",
"dlQbPhqGro"
]
}
}
Search
The following request performs a search query on the return resource:
curl -g -X POST \
'https://{{your_domain}}.commercelayer.io/metrics/returns/search' \
-H 'Accept: application/vnd.api.v1+json' \
-H 'Content-Type: application/vnd.api+json' \
-H 'Authorization: Bearer {{your_access_token}}' \
-d '{
"search": {
"limit": 20,
"sort": "asc",
"sort_by": "return.created_at",
"fields": ["return.id", "return.approved_at", "market.id", "return.status"]
},
"filter": {
"return": {
"date_from": "2022-01-01T18:36:01Z",
"date_to": "2022-12-30T18:36:02Z"
},
"market": {
"names": {
"in": ["USA"]
}
}
}
}'
On success, the API responds with a 200 OK
status code, returning the requested fields in the data
object and additional information alongside pagination in the meta
object:
{
"data": [
{
"id": "QZpXvupjZY",
"approved_at": "2022-01-12T15:27:34.435Z",
"status": "received",
"market": {
"id": "AjRevhvqvo"
}
}
],
"meta": {
"pagination": {
"record_count": 1,
"cursor": null
},
"type": "search",
"trace_id": "6b0aebae-07e1-439c-ad9a-2ec29bb04b3f",
"mode": "test",
"organization_id": "mzRmbZFPyO",
"market_ids": [
"AjRevhvqvo",
"dlQbPhqGro"
]
}
}
Last updated