• What's new

Updates To The Mailgun Stats API

Anton Efimenko
5 min read

We know Mailgun users want to know what’s going on with their email. Back in May, we made some significant updates to our dashboard allowing users to check the delivery performance of their email. Today, we’re pleased to announce updates to our Stats API providing users the opportunity to capture more data about their emails.

We’ve updated our stats API with new features that will help Mailgun users track the status of their emails at a more granular level. The new API can now return data in chronological order with a specified resolution. Monthly, daily and hourly resolutions are now supported.

We’ve also extended the tags API so it’s now possible to provide an optional description to a tag through the API. With this update, you can also list all tags.

The Stats API for each tag are now supported and show the number of unique clicks and opens.

Key Benefits

With this update, Mailgun users will now be able to:

  • Request stats for a particular event and tag

  • Supply an optional description of a tag

  • View stats at a more granular level, including hourly resolution

Use Case

We use the same API to display our main dashboard in the Mailgun control panel. You can read more about it here.

For example, if you want to draw a graph that we have on the dashboard page for a domain example.com here is an idea on how to get the data series:

1import requests
3def _get_stats():
4 """Call Mailgun API to get the domain stats."""
5 return requests.get( "https://api.mailgun.net/v3/example.com/stats/total",
6 auth=("api", "YOUR_API_KEY"),
7 params={"event": ["accepted", "delivered", "failed"], "duration": "30d"})
9def get_series_for_graph():
10 """Returns the data series required for drawing a nice graph."""
11 # Make a request to the API.
12 response = _get_stats()
14 # Prepare empty data series.
15 series = {"Delivered": [], "Dropped": [], "Incoming": []}
17 # Iterate over all items in the response where
18 # each item represents stats for a particular day.
19 for item in response["stats"]:
20 series["Delivered"].append(item["delivered"]["smtp"])
21 series["Dropped"].append(item["failed"]["permanent"]["total"])
22 series["Incoming"].append(item["accepted"]["incoming"])
24return series

Additional Info

Check our out documentation and if you have a question, feel free to leave a comment!



Last updated on August 28, 2020

  • Related posts
  • Recent posts
  • Top posts
View all

Always be in the know and grab free email resources!

No spam, ever. Only musings and writings from the Mailgun team.

By sending this form, I agree that Mailgun may contact me and process my data in accordance with its Privacy Policy.

sign up
It's easy to get started. And it's free.
See what you can accomplish with the world's best email delivery platform.
Sign up for Free