Skip to content

Add Stats API#61

Open
piobeny wants to merge 2 commits intomainfrom
stats-api
Open

Add Stats API#61
piobeny wants to merge 2 commits intomainfrom
stats-api

Conversation

@piobeny
Copy link

@piobeny piobeny commented Mar 6, 2026

Motivation

  • Add support for the Email Sending Stats API (/api/accounts/{account_id}/stats) to the PHP SDK, enabling users to retrieve aggregated email sending statistics.

Changes

  • Add Stats class extending AbstractApi with 5 methods: get, byDomains, byCategories, byEmailServiceProviders, byDate
  • Add query param handling for array filters (sending_domain_ids, sending_streams, categories, email_service_providers)
  • Add usage example in examples/sending/stats.php
  • Update README with Stats API reference
  • Update CHANGELOG with v3.10.0 entry

How to test

  • $stats->get($startDate, $endDate) with different parameters (sendingDomainIds, sendingStreams, categories, emailServiceProviders)
  • Test grouped endpoints (byDomains, byCategories, byEmailServiceProviders, byDate) with filters

Examples

use Mailtrap\Config;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSendingClient;

$config = new Config('api_key');
$stats = (new MailtrapSendingClient($config))->stats($accountId);

// Get aggregated stats
$response = $stats->get('2026-01-01', '2026-01-31');
var_dump(ResponseHelper::toArray($response));

// Get stats with optional filters
$response = $stats->get(
    '2026-01-01',
    '2026-01-31',
    sendingDomainIds: [1, 2],
    sendingStreams: ['transactional'],
    categories: ['Welcome email'],
    emailServiceProviders: ['Gmail', 'Yahoo']
);

// Get stats grouped by date
$response = $stats->byDate('2026-01-01', '2026-01-02');

// Get stats grouped by categories
$response = $stats->byCategories('2026-01-01', '2026-01-02');

// Get stats grouped by email service providers with filters
$response = $stats->byEmailServiceProviders(
    '2026-01-01',
    '2026-01-02',
    categories: ['Welcome email']
);

// Get stats grouped by domains with filters
$response = $stats->byDomains(
    '2026-01-01',
    '2026-01-02',
    categories: ['Welcome email'],
    emailServiceProviders: ['Google']
);

piobeny and others added 2 commits March 4, 2026 15:04
…ers, byDate endpoints

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@piobeny piobeny changed the title Stats api Add Stats API Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant