Overview
The SendLayer API allows you to retrieve detailed information about email events such as deliveries, opens, clicks, bounces, and more. This guide shows you how to fetch these events and apply various filters to get the specific data you need.Prerequisites
Retrieving All Events
To get started, you can retrieve all events associated with your account. By default, this returns the most recent 5 events.Replace
<apiKey>
with your actual SendLayer API key in the request header.Example Response
When you retrieve events, you’ll receive data in this format:Filtering Events
You can apply various filters to narrow down the events you want to retrieve. This is useful for analyzing specific time periods, event types, or individual emails.Filter by Date Range
Retrieve events within a specific time period using Unix timestamps.Filter by Event Type
You can filter events by type. Here is an example:opened
: Recipient opened the emailclicked
: Recipient clicked a link in the emailunsubscribed
: Recipient unsubscribed from emailscomplained
: Recipient marked email as spamdelivered
: Email successfully delivered to recipient’s inboxfailed
: Email failed to deliver and bounced backaccepted
: Email was accepted by the recipient’s email server. In some cases, this may be seen asaccepted-by-system
rejected
: Email was rejected by the recipient’s email server
Filter by Message ID
Retrieve events for a specific email using its Message ID.Pagination and Result Limits
Control how many events to retrieve and implement pagination.Combining Filters
You can combine multiple filters to get very specific results.Available Parameters
The events API supports the following parameters for filtering and pagination:Parameter | Type | Required | Description |
---|---|---|---|
startDate | number | No | Unix timestamp for the start of the date range |
endDate | number | No | Unix timestamp for the end of the date range |
event | string | No | Filter by event type (accepted, rejected, failed, delivered, opened, clicked, unsubscribed, complained) |
messageId | string | No | Filter by specific email Message ID |
startFrom | number | No | Starting position for pagination (default: 0) |
retrieveCount | number | No | Number of events to retrieve (default: 5) |
Event Data Structure
Each event contains detailed information about what happened to your email:Event Fields Explained
- Event: The type of event that occurred
- LoggedAt: Unix timestamp when the event was logged
- LogLevel: Log level (usually “info”)
- Message: Email message details including headers and metadata
- Recipient: The email address of the recipient
- Reason: Human-readable description of what happened
- Ip: IP address where the event occurred (for opens/clicks)
- Geolocation: Geographic location data (for opens/clicks)
Best Practices
- Use Date Filters: Always specify date ranges when retrieving events to avoid overwhelming results
- Implement Pagination: Use
startFrom
andretrieveCount
for large datasets - Cache Results: Store event data locally to avoid repeated API calls
- Monitor Rate Limits: Be mindful of API rate limits when making frequent requests
- Error Handling: Implement proper error handling for API failures
- Regular Polling: Set up regular intervals to check for new events
FAQ
How far back can I retrieve events?
How far back can I retrieve events?
SendLayer stores event data for a limited time period. This varies by account and is subject to change. Contact support for specific retention details for your account.
How often should I check for new events?
How often should I check for new events?
For real-time monitoring, check every few minutes. For batch processing, hourly or daily checks are usually sufficient.
What timezone are the timestamps in?
What timezone are the timestamps in?
All timestamps are in Unix timestamp format (seconds since epoch) and are in UTC timezone.