Skip to content

Query account metrics

Request

Queries filtered metrics for an account

Security
basicAuth
Bodyrequired
startstring

A start date (default: 7 days before current time). Must be in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14

endstring

An end date (default: current time). Must be in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14

resolutionstring

A resolution in the format of 'day' 'hour' 'month'. Default is day.

durationstring

A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.

dimensionsArray of strings

Attributes of the metric data such as 'subaccount'. See dimensions

metricsArray of strings

Name of the metrics to receive the stats for such as 'processed_count'. See metrics

filterobject(github.com-mailgun-analytics-client-golang-FilterPredicateGroup)

Filters to apply to the query.

include_subaccountsboolean

Include stats from all subaccounts.

include_aggregatesboolean

Include top-level aggregate metrics.

curl -i -X POST \
  -u '<username>:<password>' \
  https://api.mailgun.net/v1/analytics/metrics \
  -H 'Content-Type: application/json' \
  -d '{
    "start": "Mon, 13 Nov 2023 20:56:50 -0600",
    "end": "Wed, 20 Dec 2023 20:56:50 -0600",
    "resolution": "month",
    "duration": "1m",
    "dimensions": [
      "time"
    ],
    "metrics": [
      "accepted_count",
      "delivered_count",
      "clicked_rate",
      "opened_rate"
    ],
    "filter": {
      "AND": [
        {
          "attribute": "domain",
          "comparator": "=",
          "values": [
            {
              "label": "example.com",
              "value": "example.com"
            }
          ]
        }
      ]
    },
    "include_subaccounts": true,
    "include_aggregates": true
  }'

Responses

A 200 response

Bodyapplication/json
startstring
endstring
resolutionstring
durationstring
dimensionsArray of strings
paginationobject(github.com-mailgun-analytics-client-golang-Pagination)
itemsArray of objects(github.com-mailgun-analytics-internal-api-RegularItem)required
aggregatesobject(github.com-mailgun-analytics-internal-api-RegularAggregates)
Response
{ "start": "Mon, 13 Nov 2023 20:56:50 -0600", "end": "Wed, 20 Dec 2023 20:56:50 -0600", "resolution": "month", "duration": "1m", "pagination": { "sort": "timestamp:asc", "skip": 1, "limit": 10, "total": 1000 }, "items": [ {}, {} ], "aggregates": { "metrics": {} } }