Retrieving Daily Bounce Reports in Mailgun

Hey everyone,

I’m trying to figure out if there’s a way to fetch bounce data for the current day using Mailgun’s API. I’m wondering if we can use something like this:

GET /domain/bounces/today

or maybe:

GET /domain/bounces/current_date

Is this even possible? I’ve been playing around with the API and came up with this code snippet:

public static ApiResponse FetchTodaysBounces()
{
    var apiClient = new MailgunApiClient();
    apiClient.SetBaseUrl("https://api.mailgun.net/v3");
    apiClient.SetAuthCredentials("api", "your-secret-api-key-here");

    var request = new BounceRequest();
    request.AddDomainParam("yourdomain.com");
    request.SetEndpoint("/bounces/today");

    return apiClient.SendRequest(request);
}

Does anyone know if this approach would work? Or if there’s a better way to get bounce data for just today? Thanks for any help!

hey there! i’ve dealt with this before. mailgun doesn’t have a specific ‘today’ endpoint, but you can use the regular /bounces with some date filters. try this:

GET /v3/yourdomain.com/bounces?begin=2023-11-15&end=2023-11-16

just replace the dates with today’s date and tomorrow’s. it’ll give u all the bounces for today. hope that helps!

I’ve actually been working with Mailgun’s API quite a bit lately, and I can share some insights on fetching bounce data. Unfortunately, there isn’t a direct endpoint for ‘today’s’ bounces like you’re hoping for. However, you can achieve what you want with a slight modification to your approach.

Instead of using a non-existent ‘/bounces/today’ endpoint, you’ll want to use the standard ‘/bounces’ endpoint with query parameters to filter the results. Here’s what I’ve found works well:

var request = new BounceRequest();
request.AddDomainParam("yourdomain.com");
request.SetEndpoint("/bounces");
request.AddParameter("begin", DateTime.Today.ToString("yyyy-MM-dd"));
request.AddParameter("end", DateTime.Today.AddDays(1).ToString("yyyy-MM-dd"));

This way, you’re explicitly setting the date range to cover just today. It’s been reliable in my experience, though you might need to adjust for timezone differences depending on your specific use case. Hope this helps!

I’ve encountered this issue before, and there’s a straightforward solution. Mailgun doesn’t offer a specific endpoint for ‘today’s’ bounces, but you can use the standard /bounces endpoint with date filters. Here’s a more efficient approach:

var client = new RestClient("https://api.mailgun.net/v3");
client.Authenticator = new HttpBasicAuthenticator("api", "your-api-key");

var request = new RestRequest($"{yourDomain}/bounces", Method.GET);
request.AddParameter("begin", DateTime.UtcNow.Date.ToString("o"));
request.AddParameter("limit", 300);

var response = client.Execute(request);

This method uses UTC dates to avoid timezone issues and sets a reasonable limit. You can adjust the limit based on your needs. Remember to handle pagination if you expect more than 300 bounces daily.