Back to main menu

Product

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...

PUBLISHED ON

PUBLISHED ON

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:

import requests

def _get_stats(): """Call Mailgun API to get the domain stats.""" return requests.get( "https://api.mailgun.net/v3/example.com/stats/total", 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!

https://documentation.mailgun.com/api-stats.html

https://documentation.mailgun.com/api-tags.html

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.

Email

5 min

Build Laravel 11 email authentication with Mailgun and Digital Ocean

Read More

Mailgun statistics.

Product

4 min

Sending email using the Mailgun PHP API

Read More

Statistics on deliverability.

Deliverability

5 min

Here’s everything you need to know about DNS blocklists

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