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

We went to Unspam! Here’s what we learned

Here’s how Really Good Email’s describes Unspam, A rebel conference for email folks who hate boring conferences… unexpected, unconventional, and unforgettable. We know that...

Read more

Weekly product update: New events API available for private beta

We believe in giving our customers full transparency into what is happening with their emails. That is why we show our customers...

Read more

Weekly product update: Support center and improvements to domains and events APIs

This week we worked on a few things that we think will make a big impact for...

Read more

Popular posts

Email inbox.

Build Laravel 10 email authentication with Mailgun and Digital Ocean

When it was first released, Laravel version 5.7 added a new capability to verify user’s emails. If you’ve ever run php artisan make:auth within a Laravel app you’ll know the...

Read more

Mailgun statistics.

Sending email using the Mailgun PHP API

It’s been a while since the Mailgun PHP SDK came around, and we’ve seen lots of changes: new functionalities, new integrations built on top, new API endpoints…yet the core of PHP...

Read more

Statistics on deliverability.

Here’s everything you need to know about DNS blocklists

The word “blocklist” can almost seem like something out of a movie – a little dramatic, silly, and a little unreal. Unfortunately, in the real world, blocklists are definitely something you...

Read more

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