Updates to the Mailgun Stats API

We’re pleased to announce updates to our Stats API providing users the opportunity to capture more data about their emails. Read more...



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 here is an idea on how to get the data series:

import requests

def _get_stats(): """Call Mailgun API to get the domain stats.""" return requests.get( "", auth=("api", "YOUR_API_KEY"), params={"event": ["accepted", "delivered", "failed"], "duration": "30d"})

def get_series_for_graph(): """Returns the data series required for drawing a nice graph.""" # Make a request to the API. response = _get_stats()

# Prepare empty data series. series = {"Delivered": [], "Dropped": [], "Incoming": []}

# Iterate over all items in the response where # each item represents stats for a particular day. for item in response["stats"]: series["Delivered"].append(item["delivered"]["smtp"]) series["Dropped"].append(item["failed"]["permanent"]["total"]) series["Incoming"].append(item["accepted"]["incoming"])

return series

Additional Info

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

Related readings

Closing the loop between your customer data and your email data

One of the latest tech buzz phrases is “big data”. Once you put something on the internet you will (hopefully) have plenty of data to choose from – the hard part is tying data from disparate sources all together into actionable insights. This is what “big data” is supposed to help with…I think.

Read more

New events API, detailed email tracking and search

The completely refactored Events API makes it easy and fast to determine exactly what happened with each and every one of your emails.

Read more

Mailgun launches new reporting dashboard

The humble beginnings of Mailgun's reporting dashboard, which shows users just how well their messages are performing.

Read more

Popular posts

Mailgun iconSee what you can accomplish with the world's best email delivery platform. It's easy to get started.Let's get sending
CTA icon Mailgun Icon