Skip to Content

Contacts API

Retrieve aggregated engagement data per recipient across all campaigns.

List Contacts

Get a list of all contacts with their engagement metrics.

Endpoint

GET /api/contacts

Query Parameters

ParameterTypeRequiredDescription
searchstringNoFilter contacts by email address

Example Request

curl -X GET "NEXT_PUBLIC_BASE_URL/api/contacts?search=john" \ -H "x-api-key: your-api-key"

Response Schema

FieldTypeDescription
emailstringRecipient email address
totalEmailsnumberTotal emails sent to this contact
totalOpensnumberTotal open events
totalClicksnumberTotal click events
campaignsstring[]Campaign names the contact received
engagementScorenumberScore from 0 to 100
lastActivitystringISO 8601 timestamp of most recent activity

Engagement Score Formula

openRate = totalOpens / totalEmails clickRate = totalClicks / totalEmails engagementScore = min(100, round((openRate * 60 + clickRate * 40) * 100))

Example Response

[ { "email": "john@example.com", "totalEmails": 24, "totalOpens": 18, "totalClicks": 7, "campaigns": ["Welcome Series", "Newsletter January"], "engagementScore": 57, "lastActivity": "2024-03-14T16:45:00.000Z" }, { "email": "jane@example.com", "totalEmails": 12, "totalOpens": 12, "totalClicks": 5, "campaigns": ["Newsletter January"], "engagementScore": 77, "lastActivity": "2024-03-13T09:30:00.000Z" } ]

Get Contact Detail

Get detailed engagement information for a specific contact, including a full activity timeline.

Endpoint

GET /api/contacts/:email

Path Parameters

ParameterTypeDescription
emailstringURL-encoded email address

Example Request

curl -X GET NEXT_PUBLIC_BASE_URL/api/contacts/john%40example.com \ -H "x-api-key: your-api-key"

Response Schema

FieldTypeDescription
emailstringRecipient email address
totalEmailsnumberTotal emails sent
totalOpensnumberTotal open events
totalClicksnumberTotal click events
campaignsstring[]Campaign names
engagementScorenumberScore from 0 to 100
lastActivitystringISO 8601 most recent activity
firstSeenstringISO 8601 first email sent
openRatenumberOpens per email ratio
clickRatenumberClicks per email ratio
timelineTimelineEvent[]Chronological list of events

TimelineEvent Schema

FieldTypeDescription
typestring"sent", "opened", or "clicked"
timestampstringISO 8601 event timestamp
subjectstringEmail subject line
campaignstringCampaign name (optional)
linkstringClicked URL (only for "clicked" events)

Example Response

{ "email": "john@example.com", "totalEmails": 24, "totalOpens": 18, "totalClicks": 7, "campaigns": ["Welcome Series", "Newsletter January"], "engagementScore": 57, "lastActivity": "2024-03-14T16:45:00.000Z", "firstSeen": "2024-01-05T08:00:00.000Z", "openRate": 0.75, "clickRate": 0.29, "timeline": [ { "type": "clicked", "timestamp": "2024-03-14T16:45:00.000Z", "subject": "March Newsletter", "campaign": "Newsletter January", "link": "https://example.com/promo" }, { "type": "opened", "timestamp": "2024-03-14T16:40:00.000Z", "subject": "March Newsletter", "campaign": "Newsletter January" }, { "type": "sent", "timestamp": "2024-03-14T10:00:00.000Z", "subject": "March Newsletter", "campaign": "Newsletter January" } ] }

Error Responses

StatusDescription
401 UnauthorizedInvalid or missing API key
404 Not FoundContact not found in your organization

Example Error

{ "error": "Contact not found" }
Last updated on
Mailpulse Documentation