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"]
          }
        }
    }
}'

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"]
          }
        }
    }
}'

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"]
          }
        }
    }
}'

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"]
          }
        }
    }
}'

Last updated