# SmartEmailing API v3 > Interactive documentation for people: https://app.smartemailing.cz/docs/api/v3/index.html > ๐ŸŒ **Base URL** โ€” `https://app.smartemailing.cz/api/v3` --- ## ๐Ÿ”‘ Authentication HTTP Basic Auth โ€” use your **email** as username and **API key** as password. Find your API key in **Account Settings โ†’ API keys**. --- ## ๐Ÿ“จ Request Format > All requests must include header `Content-Type: application/json` --- ## ๐Ÿšฆ Rate Limiting Requests are rate-limited **per account** using continuously refilling token buckets: | Policy | Burst capacity | Sustained refill rate | |---|---|---| | `per-second` | 2 500 requests | 4 requests/second | | `daily-limit` | 100 000 requests | 100 000 requests/day (โ‰ˆ1.16 requests/second) | Buckets refill **continuously** โ€” there is no midnight reset. After a burst is exhausted, capacity keeps returning at the sustained rate. Every response includes rate limit headers for the policy closest to exhaustion: - `X-RateLimit-Limit` โ€” burst capacity of the reported policy - `X-RateLimit-Remaining` โ€” remaining requests in the reported policy - `X-RateLimit-Reset` โ€” unix timestamp when the reported bucket is fully refilled When a limit is exceeded, the API responds with **`429 Too Many Requests`** and a `Retry-After` header (whole seconds to wait). Rejected requests do not consume the daily quota. > Respect `Retry-After`, use exponential backoff, and watch `X-RateLimit-Remaining` to throttle proactively. --- ## ๐Ÿ“„ Pagination Collection endpoints accept `limit` (default `500`, max `500`) and `offset` (default `0`) query parameters. [Email Metrics](https://app.smartemailing.cz/docs/api/v3/guides/email-metrics.md) and [Event Streams](https://app.smartemailing.cz/docs/api/v3/guides/event-streams.md) use a cursor instead โ€” see their guides. --- ## ๐Ÿค Partner Integrations > Building an integration for **multiple accounts**? Include this header: > > `partner-id: your_eshop_solution` --- ## ๐Ÿ“ฆ Response Structure ```json { "status": "ok", "meta": [], "data": { ... } } ``` > **`ok`** โ†’ 200 Success ยท **`created`** โ†’ 201 Created ยท **`error`** โ†’ 4xx See `message` field --- ## ๐Ÿ“Š Email Metrics **The main way to get statistics of your emails.** Whatever numbers you need โ€” for a dashboard, a report for your client, a BI tool or your own app โ€” `GET /email-statistics/metrics` is the endpoint to use. Delivery and bounce rates, opens, clicks, unsubscribes, spam complaints, revenue, top links, devices and mail clients: per campaign, per day, week, month or year, per recipient domain, per mailbox provider or per contact engagement level โ€” or any combination of them. The only thing it does not give you is **individual events** (who opened or clicked which message and when). For those use **Event Streams**. | You need | Use | |---|---| | Numbers โ€” totals, rates, trends, breakdowns | **Email Metrics** | | Every single delivery, open, click, bounce or unsubscribe of each contact | **Event Streams** | It replaces `/email-performance-overview`. See the [Email Metrics](https://app.smartemailing.cz/docs/api/v3/guides/email-metrics.md) guide. --- ## ๐Ÿ”„ Event Streams Need every open, click, bounce or unsubscribe in your CRM or data warehouse? **Event streams** (topic `email`) deliver all email events of your account in order, exactly from where you left off โ€” no polling with time windows, no lost events, no daily full re-syncs. See the [Event Streams](https://app.smartemailing.cz/docs/api/v3/guides/event-streams.md) guide. It replaces `/campaign-stats-sent` and `/email-statistic-events-jsonl`. **Use event streams instead of the `email_open`, `email_click`, `delivery_status` and `unsubscribed_contact` webhooks** โ€” nothing is lost when your server is down, no flood of requests during large sends, and no public endpoint, queue or worker to run. --- ## ๐ŸŒ… API CSV ends on 2027-03-01 API CSV (`/api/csv/โ€ฆ`) is deprecated and will be switched off on **2027-03-01**. The [API CSV sunset page](https://app.smartemailing.cz/docs/api/csv/index.html) lists every API CSV method with its replacement in API v3. --- ## ๐Ÿ“ฅ OpenAPI Specification Machine-readable API specification is available for download: - **JSON** โ€” [openapi.json](https://app.smartemailing.cz/docs/api/v3/openapi.json) - **YAML** โ€” [openapi.yaml](https://app.smartemailing.cz/docs/api/v3/openapi.yaml) --- ## ๐Ÿค– Model Context Protocol (MCP) SmartEmailing exposes an MCP server for AI assistants (Claude, Cursor, and other MCP-compatible clients). > **Endpoint** โ€” `https://app.smartemailing.cz/mcp` ยท **Protocol** โ€” `2025-03-26` ยท **Auth** โ€” OAuth Bearer token Clients auto-discover available tools via the standard `tools/list` method. No additional configuration is needed โ€” just point your MCP client to the endpoint and authenticate. # Email Metrics โ€” SmartEmailing API v3 > Interactive documentation for people: https://app.smartemailing.cz/docs/api/v3/index.html#tag/email-metrics Email metrics are **the main endpoint for the statistics of your emails** โ€” use it for practically every report, dashboard or export of numbers. It returns deliveries, bounces, opens, clicks, unsubscribes, spam complaints and revenue aggregated into **buckets**: per campaign, per period, per recipient domain, per mailbox provider, per contact engagement level, or any combination of them. One endpoint: `GET /email-statistics/metrics`. It measures each **campaign** separately โ€” each newsletter, each email node of an automation and each of its A/B variants, each autoresponder โ€” not just your account as a whole. One such measured campaign is an **email statistic** (not a single message sent to one contact) โ€” see **Email statistics โ€” what you are measuring** below. ## ๐ŸŽฏ What it is for - **Campaign results** โ€” how did yesterday's campaign do? Delivery, open, click and unsubscribe rates, revenue and top links of one campaign or of all of them. - **Trends over time** โ€” month-by-month or week-by-week development of your open rate, clicks or revenue; compare this year with the last one. - **Deliverability** โ€” bounce rates and their reasons per mailbox provider (Gmail, Seznam, Apple, โ€ฆ) or recipient domain; spot a provider that starts rejecting your emails. - **Audience quality** โ€” how contacts of each engagement level react; how much of your traffic comes from bots and privacy proxies instead of people. - **Revenue attribution** โ€” orders and revenue brought by each campaign, direct and assisted, in the original currencies and in your base currency. - **Automations** โ€” performance of every email of an automation, with the automation and node it was sent from. - **Client reporting and BI** โ€” feed dashboards, Looker Studio, Power BI, a data warehouse or a report for your client with daily or monthly numbers. **When not to use it:** when you need individual events of individual contacts โ€” to update a CRM after every click, to trigger your own actions, or to keep a copy of the raw activity. That is what **Event Streams** are for. A common setup uses both: Event Streams for per-contact activity, Email Metrics for the numbers. --- ## ๐Ÿš€ Quick start **1. One bucket per campaign:** ```bash curl -u "you@example.com:API_KEY" \ "https://app.smartemailing.cz/api/v3/email-statistics/metrics?group_by=email_statistic_id" ``` ```json { "status": "ok", "meta": { "cursor": "1.1xyC2GUV3dwC8WTFHIqHCYeAr3faN_JYPcoKZh8O68D2oEu2CltOZQWU", "has_more": true, "interaction_sources": ["human", "proxied", "bot"] }, "data": [ { "timeframe": { "first_email_sent_at": "2026-03-11T14:00:00Z", "last_email_sent_at": "2026-03-11T15:00:00Z", "duration": "P0Y0M0DT1H0M0S" }, "last_modified_at": "2026-06-22T09:19:38Z", "dimensions": {"email_statistic_id": "0167adc838474c628001cfb99f7048d2"}, "metrics": { "delivery": { "total": 930, "sent": 930, "delivered": 928, "soft_bounced": 2, "hard_bounced": 0, "total_bounced": 2, "waiting_for_delivery": 0, "delivery_rate": 0.9978, "bounce_rate": 0.0022, "based_on": "sent" }, "interactions": { "opens": {"unique": 320, "total": 487, "open_rate": 0.3448, "based_on": "delivered"}, "clicks": { "unique": 18, "total": 27, "click_rate": 0.0194, "click_rate_based_on": "delivered", "click_to_open_rate": 0.0563, "click_to_open_rate_based_on": "unique_opens" }, "unsubscribes": {"total": 3, "unsubscribe_rate": 0.0032, "based_on": "delivered"}, "spam_complaints": {"total": 0, "spam_complaint_rate": 0.0, "based_on": "delivered"}, "web_version_views": {"unique": 0, "total": 0}, "prints": {"unique": 0, "total": 0} } } } ] } ``` **2. Read the next page** โ€” `has_more: true` means there is more. Send **the same request** again and add `&cursor=` with the value of `meta.cursor`: ```bash curl -u "you@example.com:API_KEY" \ "https://app.smartemailing.cz/api/v3/email-statistics/metrics?group_by=email_statistic_id&cursor=1.1xyC2GUV3dwC8WTFHIqHCYeAr3faN_JYPcoKZh8O68D2oEu2CltOZQWU" ``` Repeat until `"has_more": false`. That's the whole integration โ€” see **Reading all pages โ€” step by step** below. **Full statistics of one email** โ€” filter by its `email_statistic_id` and ask for every section; the result is a single bucket on a single page: ```bash curl -u "you@example.com:API_KEY" \ "https://app.smartemailing.cz/api/v3/email-statistics/metrics?group_by=email_statistic_id&email_statistic_ids=0167adc838474c628001cfb99f7048d2&include=conversions,bounce_reasons,unsubscribe_reasons,clicked_urls,devices,email_clients,context" ``` ๐Ÿ“‹ The full response is the example **one-email-full** of [Read email metrics](https://app.smartemailing.cz/docs/api/v3/openapi/email-metrics.json). --- ## ๐Ÿ”Ž I want โ€ฆ โ†’ call this Copy the request, put in your values, and read the result where the last column says. All requests are `GET https://app.smartemailing.cz/api/v3/email-statistics/metrics?โ€ฆ`; read all pages when `has_more` is `true`. | I want | Query | Where is the result | |---|---|---| | A list of my sent emails with their names | `group_by=email_statistic_id&include=context` | `data[].dimensions.email_statistic_id`, `data[].context.email_statistic.name` | | Emails I sent in the last month | `group_by=email_statistic_id&include=context&time_from=` | `data[].context.email_statistic.name`, `data[].timeframe.first_email_sent_at` | | Open rate of one email | `group_by=email_statistic_id&email_statistic_ids=` | `data[0].metrics.interactions.opens.open_rate` | | Everything about one email | `group_by=email_statistic_id&email_statistic_ids=&include=conversions,bounce_reasons,unsubscribe_reasons,clicked_urls,devices,email_clients,context` | `data[0]` โ€” see the example **one-email-full** | | Top links of one email | `group_by=email_statistic_id&email_statistic_ids=&include=clicked_urls` | `data[0].metrics.interactions.clicks.dimensions.links` | | Revenue of every email this year | `group_by=email_statistic_id&time_from=2026-01-01T00:00:00Z&include=conversions` | `data[].metrics.interactions.conversions.order.total.revenue_in_base_currency.revenue.with_vat` | | Who bought after which email, contact by contact | not here โ€” read the `email.converted` events of **Event Streams** | `data.contact`, `data.details.order`, `data.details.attribution` of each event | | Open and click rate per month | `group_by=time:month` | `data[].dimensions["time:month"]`, `data[].metrics.interactions.opens.open_rate`, `โ€ฆclicks.click_rate` | | Results of each email per day | `group_by=email_statistic_id,time:day&time_from=2026-03-01T00:00:00Z` | `data[].dimensions`, `data[].metrics` | | Bounces by mailbox provider (Gmail, Seznam, โ€ฆ) | `group_by=infra_provider&include=bounce_reasons` | `data[].dimensions.infra_provider`, `data[].metrics.delivery.bounce_rate`, `โ€ฆdelivery.bounce_reasons` | | Totals of everything I have ever sent | *(no parameters)* | `data[0].metrics` | | Engagement per contact engagement level | `group_by=engagement_level&interaction_sources=human,proxied` | `data[].dimensions.engagement_level`, `data[].metrics.interactions` | | How much of the opens are bots | two requests: `interaction_sources=bot` and `interaction_sources=human,proxied` | `data[0].metrics.interactions.opens` of each | | Nightly export into a data warehouse | `group_by=email_statistic_id,time:day&time_from=<3 days ago>` | `data[]` โ€” re-read the last few days every night, their numbers keep growing as late opens and clicks come in. For every single event use **Event Streams**. | | Any of the above for real people only | add `&interaction_sources=human,proxied` | the same place | Rates are fractions: `0.3448` means **34.48 %** โ€” multiply by 100. --- ## ๐Ÿ†” Email statistics โ€” what you are measuring An **email statistic** is one measured campaign: a newsletter, one email node of an automation, an autoresponder, one tag of custom or transactional emails. It is **not a single message** โ€” a newsletter sent to 10 000 contacts is 10 000 messages, but one email statistic. Every message you send is counted into exactly one email statistic, and everything in this API โ€” metrics, events, revenue โ€” is tied to it by its `email_statistic_id`, a 32-character hex string such as `0167adc838474c628001cfb99f7048d2`. A single message has its own ID, `email_message_id` in **Event Streams**. It is not one summary number per account or per campaign type. It is as fine-grained as your emails are: | What you send | Email statistics | `type` | |---|---|---| | A newsletter | one per newsletter | `newsletter` | | An automation | **one per email node** โ€” every email of the automation is measured on its own | `automation` | | An A/B test in an automation | **one per variant** โ€” each variant is its own node, so you compare them directly | `automation` | | An autoresponder | one for its whole life โ€” add `group_by=time:day` to see each day | `autoresponder` | | Custom and transactional emails sent through the API | **one per tag** โ€” give different emails different tags to measure them separately | `custom_email`, `transactional_email` | | Opt-in (double opt-in confirmation) emails | one per account | `opt_in_email` | | Trigger campaigns (older feature) | one per trigger action | `trigger_action` | That is what turns questions like *"which email of my onboarding converts best?"*, *"did variant B beat variant A?"* or *"how does the order confirmation do on Gmail?"* into a single request. **How an email statistic lives:** - It appears with the **first message sent**. Before that it does not exist and is not listed. - It is **long-lived**. An autoresponder or an automation node keeps adding every new message into the same statistic for as long as it sends. If you edit the email in an automation node, the statistic goes on โ€” the numbers before and after the change are together. To compare two versions, put the new one into a new node or an A/B split. - Its `name` is the name the campaign or node had when its first message was sent. The current names of the automation and the node, and the current subject, are in `include=context`. - It is **never deleted**. When you delete the campaign, the automation or the node, the statistic and its numbers stay; only the parts of `context` describing the deleted object become `null`. ### Where do I get the IDs? **Ask for the list โ€” with the numbers right away:** one bucket per email statistic, described by `include=context`. Add `time_from` to see only the emails sent since then: ```bash curl -u "you@example.com:API_KEY" \ "https://app.smartemailing.cz/api/v3/email-statistics/metrics?group_by=email_statistic_id&include=context&time_from=2026-10-01T00:00:00Z" ``` Each bucket carries the ID in `dimensions.email_statistic_id`, when it was first and last sent in `timeframe`, and what it is in `context`: ```json { "timeframe": {"first_email_sent_at": "2026-10-02T08:00:00Z", "last_email_sent_at": "2026-11-12T19:00:00Z", "duration": "P0Y1M10DT11H0M0S"}, "dimensions": {"email_statistic_id": "11f1574b44671a1882b63cecef38fa8c"}, "context": { "email_statistic": {"id": "11f1574b44671a1882b63cecef38fa8c", "type": "automation", "name": "Welcome email โ€” variant A"}, "email": {"id": 5821, "subject": "Welcome aboard!", "tracking_parameters": [{"key": "utm_source", "value": "onboarding"}]}, "automation": { "id": "a7c3e9f1b2d44c6e8a0f1d2c3b4a5e6f", "name": "Onboarding", "labels": ["onboarding"], "node": {"id": "c2e4a6b8d0f24e6a8c0e2a4c6e8a0c2e", "label": "Welcome email โ€” variant A"} } }, "metrics": { โ€ฆ } } ``` Read all pages (see **Reading all pages โ€” step by step**), then **find the one you need:** | I want | Look for | |---|---| | All emails of one automation | `context.automation.id` | | One email node or one A/B variant | `context.automation.node.id` | | My order confirmation | `context.email_statistic.type: transactional_email` (or `custom_email`) + `context.email_statistic.name` = its tag | Keep the IDs and filter later reports by them with `email_statistic_ids=โ€ฆ`. **From Event Streams:** every event carries the same ID in `data.email_statistic.id`, together with the type and name. The first `email.delivered` event of a new email tells you that a new email statistic exists. --- ## ๐Ÿ“„ Reading all pages โ€” step by step Large reports come in pages. The server decides how many buckets a page has โ€” it may differ between requests and change over time, so always read until `has_more` is `false`. Reports without `include` use large pages, so most of them โ€” monthly or daily totals, one row per campaign โ€” fit into a single response. That keeps them easy to load into BI tools such as Power BI, Looker Studio or Excel. Still check `has_more`: a long period or many campaigns can need more pages. **Page 1** โ€” your normal request: ``` GET /email-statistics/metrics?group_by=email_statistic_id&include=conversions ``` ```json {"status": "ok", "meta": {"cursor": "1.AAAAโ€ฆ", "has_more": true, "interaction_sources": ["human", "proxied", "bot"]}, "data": [ โ€ฆbucketsโ€ฆ ]} ``` `has_more: true` = there is another page. Take the value of `meta.cursor`. **Page 2** โ€” **the same request, copied character by character**, plus `&cursor=` with that value: ``` GET /email-statistics/metrics?group_by=email_statistic_id&include=conversions&cursor=1.AAAAโ€ฆ ``` ```json {"status": "ok", "meta": {"cursor": "1.BBBBโ€ฆ", "has_more": true, "interaction_sources": ["human", "proxied", "bot"]}, "data": [ โ€ฆnext bucketsโ€ฆ ]} ``` **Page 3** โ€” the same request again, with the **new** cursor `1.BBBBโ€ฆ`: ``` GET /email-statistics/metrics?group_by=email_statistic_id&include=conversions&cursor=1.BBBBโ€ฆ ``` ```json {"status": "ok", "meta": {"cursor": null, "has_more": false, "interaction_sources": ["human", "proxied", "bot"]}, "data": [ โ€ฆthe last 12 bucketsโ€ฆ ]} ``` `has_more: false` = **done**. You have all buckets โ€” no bucket is missing and none comes twice. โœ… **Rules** - Stop when `has_more` is `false` โ€” never by the number of items in `data`. - Always use the cursor from the **last** response, never the first one again. - The cursor goes into the URL (query string), never into a request body. It has only URL-safe characters, so paste it as it is. - Read all pages in one run. A cursor is for the next page now, not for tomorrow โ€” tomorrow start again from page 1. - Buckets come in a stable order: by the `group_by` dimensions in the order you listed them; `time:*` chronologically, the others by value. - Counters keep growing while people open and click, so a later page may be read a moment later than an earlier one. That is fine for reports; just don't mix pages of different runs. โŒ **Common mistakes** | You did | You get | Fix | |---|---|---| | Changed or added a parameter on page 2 (another `include`, `time_to` = now, โ€ฆ) | `400 invalid-cursor` | Send exactly the same parameters as on page 1; only `cursor` is added. | | Sent the cursor of page 1 again | Page 2 again and again | Always take `meta.cursor` from the last response. | | Put the cursor into a JSON body | Page 1 again | `cursor` is a query parameter of the `GET`. | | Stored the cursor and used it next day | Old position in a report that has changed since | Start every run from page 1. | **PHP** (Guzzle) โ€” all buckets into one array: ```php $client = new GuzzleHttp\Client([ 'base_uri' => 'https://app.smartemailing.cz/api/v3/', 'auth' => ['you@example.com', 'API_KEY'], 'timeout' => 60, ]); $query = [ 'group_by' => 'email_statistic_id', 'time_from' => '2026-01-01T00:00:00Z', 'include' => 'conversions', ]; $buckets = []; do { $response = $client->get('email-statistics/metrics', ['query' => $query]); $page = json_decode((string) $response->getBody(), true); array_push($buckets, ...$page['data']); $query['cursor'] = $page['meta']['cursor']; // the only thing that changes } while ($page['meta']['has_more']); ``` **Python** (requests) โ€” monthly numbers into `metrics.csv`, ready to open in Excel: ```python import csv import requests session = requests.Session() session.auth = ("you@example.com", "API_KEY") url = "https://app.smartemailing.cz/api/v3/email-statistics/metrics" params = {"group_by": "time:month", "time_from": "2025-01-01T00:00:00Z", "interaction_sources": "human,proxied"} with open("metrics.csv", "w", newline="") as file: writer = csv.writer(file) writer.writerow(["month", "delivered", "open rate %", "click rate %", "unsubscribes"]) while True: response = session.get(url, params=params, timeout=60) response.raise_for_status() page = response.json() for bucket in page["data"]: delivery = bucket["metrics"]["delivery"] interactions = bucket["metrics"]["interactions"] writer.writerow([ bucket["dimensions"]["time:month"], delivery["delivered"], round(interactions["opens"]["open_rate"] * 100, 2), round(interactions["clicks"]["click_rate"] * 100, 2), interactions["unsubscribes"]["total"], ]) if not page["meta"]["has_more"]: break params["cursor"] = page["meta"]["cursor"] # the only thing that changes ``` --- ## ๐Ÿง  How it works | Term | Meaning | |---|---| | **Bucket** | One item of `data` โ€” the metrics of one combination of `group_by` values, e.g. one campaign, or one month and one domain. Its key is in `dimensions`. | | **Dimension** | What a bucket is split by: `email_statistic_id`, `domain`, `infra_provider`, `engagement_level`, or one of `time:year`, `time:month`, `time:week`, `time:day`. | | **Email statistic** | One measured campaign, not a single message: a newsletter, one email node of an automation (each A/B variant on its own), an autoresponder, or one tag of custom or transactional emails. Same ID as `data.email_statistic.id` in **Event Streams**. | | **Filter** | `email_statistic_ids`, `domains`, `infra_providers`, `engagement_levels`, `time_from`, `time_to` โ€” which emails are counted at all. | | **Section** | A part of a bucket loaded on demand with `include`. | Think of the response as a table in Excel: every bucket is one row, the `group_by` dimensions are the row labels, and the metrics are the columns. - **Without `group_by`** the whole filtered range is one bucket โ€” a quick total. - **Several dimensions** โ€” `group_by=time:month,domain` gives one bucket for every month and domain that has data. At most one `time:*` dimension. - **Metrics belong to the hour the email was sent**, not to the time of the open or click. An open on Tuesday of an email sent on Monday counts in Monday's `time:day` bucket, and `time_from` / `time_to` filter by sending time. Data are kept per UTC hour, so time filters work with hour precision. - **Time buckets use the account's time zone**: `time:year` = `2026`, `time:month` = `2026-03`, `time:week` = ISO week `2026-W10` (Monday to Sunday), `time:day` = `2026-03-11`. Filters `time_from` / `time_to` are in UTC โ€” to get exactly one local month, convert its start and end: the whole of March 2026 in Prague time is `time_from=2026-02-28T23:00:00Z&time_to=2026-03-31T21:59:59Z`. - **Only buckets with data are returned.** A month without any sent email, or a domain you never sent to, has no bucket โ€” it is not a bucket with zeros. If you draw a chart, fill the missing months or days with zeros yourself. - **Domains and providers**: `domain` is the recipient's domain (about 100 most common domains by name), `infra_provider` is who hosts the mailbox (e.g. `google` for Gmail and Google Workspace, `seznam.cz`). Everything else is `_OTHER_`. Use the same values in the filters. - **Engagement level** of the contact: `A` (most engaged) โ€ฆ `E` (least engaged), `N` (new contact). - **Live numbers.** Counters grow while recipients open and click. `last_modified_at` tells when a bucket last changed. --- ## ๐Ÿงฎ Metrics Rates are fractions rounded to 4 decimals โ€” `0.3448` means **34.48 %**, multiply by 100 to show a percentage; `0.0` when their base is 0. `based_on` names the base of the rate. | Field | Meaning | |---|---| | `delivery.total` | All messages of the bucket. | | `delivery.sent` | Messages handed over for delivery (`total` without messages that were not sent and those still waiting). | | `delivery.delivered` | Accepted by the recipient's mail server. | | `delivery.soft_bounced` / `hard_bounced` / `total_bounced` | Not delivered โ€” temporary (e.g. full mailbox) / permanent (e.g. address does not exist) / both. | | `delivery.waiting_for_delivery` | Still in the queue. | | `delivery.delivery_rate`, `bounce_rate` | `delivered` / `sent`, `total_bounced` / `sent`. | | `opens.unique` / `opens.total` | Messages opened at least once / all opens. | | `opens.open_rate` | `opens.unique` / `delivered`. | | `clicks.unique` / `clicks.total` | Messages with at least one click / all clicks. | | `clicks.click_rate` | `clicks.unique` / `delivered`. | | `clicks.click_to_open_rate` | `clicks.unique` / `opens.unique`. | | `unsubscribes.total`, `unsubscribe_rate` | Unsubscribes through the email, and / `delivered`. | | `spam_complaints.total`, `spam_complaint_rate` | Marked as spam (reported by the mailbox provider), and / `delivered`. | | `web_version_views`, `prints` | Views of the web version and prints, `unique` and `total`. | | `timeframe` | First and last sending hour with data in the bucket (UTC); `duration` is the ISO 8601 duration between them. | | `last_modified_at` | Last change of the bucket's counters (UTC). | Opens and clicks count only the sources in `interaction_sources` (see below); all other numbers count everything. --- ## โž• Extra sections (`include`) Ask only for what you use โ€” every section costs extra time. Sections you did not ask for are **missing** from the bucket (not empty). A requested section of a bucket without such data has neutral values โ€” zeros and empty lists. | `include` | Adds | Content | |---|---|---| | `bounce_reasons` | `delivery.bounce_reasons` | Bounces by reason: `mx_failure`, `greylisted`, `deferred`, `email_does_not_exist`, `relay_error`, `mailbox_full`, `spam`, `final_confirmation_timeout`, `flooded_mailbox`, `suppressed`, `spam_rate_limit`. All keys always present. | | `unsubscribe_reasons` | `interactions.unsubscribes.reasons` | Unsubscribes by reason: `too_frequent`, `not_relevant`, `content_abusive`, `unsolicited`, `list_unsubscribe` (one-click unsubscribe in the mail client), `other`, `custom_reason`, `no_reason_given`, `unsubscribe_redirection`. All keys always present. | | `clicked_urls` | `clicks.dimensions.links` | `[{url, unique, total}]` โ€” the **top 10 links of the bucket** by total clicks, then one item `"url": "other"` with the rest (only when there is a rest). | | `devices` | `opens.dimensions` and `clicks.dimensions`: `device_types`, `operating_systems` | `[{name, unique, total}]`, all values, most frequent first. Device types: `desktop`, `mobile`, `tablet`, `unknown`, and `proxied` / `bot` when those sources are counted. | | `email_clients` | `opens.dimensions` and `clicks.dimensions`: `user_agents` | `[{name, unique, total}]` โ€” the **top 10 of the bucket** (e.g. `chrome`, `safari`, `apple_mpp`, `google_proxy`), the rest as `"name": "other"`. | | `conversions` | `interactions.conversions.order` | Orders attributed to the email: `direct`, `assisted` and `total` (= direct + assisted), see below. | | `context` | `context` | Who sent what โ€” see below. Requires `group_by` with `email_statistic_id`. | **Conversions** โ€” each of `direct`, `assisted` and `total`: ```json { "number_of_conversions": 2, "conversion_rate": 0.0022, "based_on": "delivered", "revenue_by_original_currency": [ { "count": 2, "revenue": {"without_vat": 139.34, "with_vat": 156.08, "currency": "EUR"}, "average_order_value": {"without_vat": 69.67, "with_vat": 78.04, "currency": "EUR"}, "margin": {"without_vat": 0.0, "with_vat": 0.0, "currency": "EUR"}, "average_margin": {"without_vat": 0.0, "with_vat": 0.0, "currency": "EUR"} } ], "revenue_in_base_currency": { "count": 2, "revenue": {"without_vat": 3371.7, "with_vat": 3776.76, "currency": "CZK"}, "average_order_value": {"without_vat": 1685.85, "with_vat": 1888.38, "currency": "CZK"}, "margin": {"without_vat": 0.0, "with_vat": 0.0, "currency": "CZK"}, "average_margin": {"without_vat": 0.0, "with_vat": 0.0, "currency": "CZK"} } } ``` `revenue_by_original_currency` has one item per currency the orders were paid in; `revenue_in_base_currency` is everything converted to your account's base currency (see **Currencies** below). Amounts are rounded to the minor units of the currency. Without conversions the amounts are zeros in the base currency and `revenue_by_original_currency` is `[]`. ### ๐Ÿ’ฐ How a conversion is attributed A **conversion** is an order from your e-shop โ€” sent through the orders API or an e-shop integration โ€” that we credit to **one message** and, through it, to the message's email statistic. Today the only conversion goal is an order. When an order arrives, we look back at what the contact did before the **time of the order**: 1. **The latest click** in any of your messages in the **5 days** before the order wins. A click at most **24 hours** before the order makes the conversion **`direct`**, an older one (1โ€“5 days) **`assisted`**. 2. **No click?** Then **the latest open** in the **24 hours** before the order wins โ€” always **`assisted`**. 3. **Neither?** The order is not attributed to any email. For example, a contact: | Did | Ordered | The conversion goes to | |---|---|---| | clicked in newsletter A at 10:00 | the same day at 18:00 | newsletter A, `direct` | | clicked in newsletter A on Monday, then in automation email B on Wednesday | on Thursday morning | email B, `direct` โ€” the latest click wins; A gets nothing | | clicked in newsletter A 3 days before | โ€” | newsletter A, `assisted` | | only opened email C 3 hours before, clicked nothing | โ€” | email C, `assisted` | | clicked in newsletter A 6 days before, opened nothing since | โ€” | nothing โ€” outside both windows | **Rules worth knowing:** - **Last touch wins.** One order is one conversion, credited to exactly one message. It is never split between emails โ€” other campaigns the contact clicked earlier get nothing for that order. - **Every order counts.** A contact who buys twice after one email brings two conversions. `conversion_rate` is conversions รท delivered messages, not the share of contacts who bought. - **The time of the order decides, not the time it reaches us.** An order imported a day late is still attributed by when it was placed โ€” as long as the click or open was already recorded. - **It is counted once, when the order first arrives.** Later changes of the same order (identified by the e-shop name and order code) โ€” status, cancellation, a different amount โ€” do not change the conversion; a cancelled order stays counted. - **Revenue lands where the email was sent.** Like everything in Email Metrics, a conversion counts in the bucket of the hour the message was **sent**: a newsletter sent in March that sells in April shows its revenue in March. The numbers of a recent campaign keep growing for up to 5 days after its last message. - **The orders must belong to your contacts.** An order is matched to the contact by its email address; orders of people who are not your contacts cannot be attributed. - **Every click and open counts โ€” whatever its source.** Attribution looks at all clicks and opens, including those our heuristic classifies as `proxied` or `bot` (see **Interaction sources** below). So an open made automatically by a privacy proxy up to 24 hours before the order can bring an `assisted` conversion. `interaction_sources` therefore does not filter `conversions`; compare `direct` and `assisted` when you want to see how much of the revenue came from a click. **Contact by contact:** every conversion is also an `email.converted` event in **Event Streams** โ€” one event per order, with the contact, the order code, the revenue and the `direct` / `assisted` attribution. Use it to see who bought what, or to send the attribution into your CRM; the numbers here and the events there are the same conversions. ### ๐Ÿ’ฑ Currencies - **Each order keeps its currency.** `revenue_by_original_currency` has one item per currency your orders were paid in โ€” EUR orders stay in EUR. - **Everything together is in the base currency.** `revenue_in_base_currency` is all orders converted to the base currency set in your account's settings, so you can add up a multi-currency shop in one number. - **The rate of the moment the order arrives.** We convert each order when it reaches SmartEmailing, at the current bank exchange rate, and keep the result โ€” later changes of the rates do not recalculate past revenue. - **Rounded per order.** Each order is converted and rounded to the minor units of the currency on its own, so a converted total can differ by a minor unit from converting the original total at once. - **Margin** is reported only when your orders are sent with it; otherwise it is zero. **Context** โ€” who sent what: `email_statistic` (`id`, `type`, `name`), `sender` (`name`, `from`, `reply_to`), `preview.url`, `email` (`id`, `subject`, `tracking_parameters`) and `automation` (`id`, `name`, `labels`, `node`). The same shape for every bucket, unknown parts are `null`. `email_statistic.type` is one of `newsletter`, `autoresponder`, `automation`, `trigger_action`, `custom_email`, `transactional_email`, `opt_in_email`. Today `sender`, `preview`, `email` and `automation` are filled only for emails sent by an automation; for other campaigns they are `null` (and `sender` has `null` values). Newsletters are now sent by automations too, so a new newsletter comes as `type: "newsletter"` **with** full context, an older newsletter as `type: "newsletter"` with its context `null`. For an email statistic that no longer exists, all values are `null`. ๐Ÿ“‹ **A full bucket with every section** is the response example **one-email-full** of [Read email metrics](https://app.smartemailing.cz/docs/api/v3/openapi/email-metrics.json). --- ## ๐Ÿ‘ค Interaction sources Every open and click is classified by who made it: | Source | Who | |---|---| | `human` | A person in a mail client. | | `proxied` | A person, but through a privacy proxy that hides the device. Still a human action. | | `bot` | Automatic โ€” security scanners, link checkers, and privacy proxies fetching the email on their own. | Not every open is a person: privacy proxies (Apple Mail Privacy Protection, Gmail image proxy) download images without anyone reading the email, and security filters follow every link. Our heuristics classify each interaction on its own from a number of signals, so the same proxy can be `bot` once and `proxied` another time. Event Streams use the same classification. `interaction_sources` (default all three) chooses which of them count. It applies to **everything about opens and clicks** โ€” `opens`, `clicks`, their rates (including `click_to_open_rate`) and their `dimensions` โ€” so the numbers always add up. It does not change `delivery`, `unsubscribes`, `spam_complaints`, `web_version_views`, `prints` or `conversions`. `meta.interaction_sources` repeats which sources the numbers come from. - **Not sure? Leave it out.** You get all opens and clicks โ€” the same numbers as `/email-performance-overview`. - **Real people only:** `interaction_sources=human,proxied` โ€” use it when you show engagement of your audience and want bots out. - **How much is bots:** one request with `bot`, one with `human,proxied` โ€” cheap without `include`. --- ## ๐Ÿ“ Limits | Limit | Value | |---|---| | Buckets per page | decided by the server | | `time:*` dimensions per request | 1 | | Links and email clients per bucket | top 10 + `other` | | Time precision | 1 hour | | History | Kept permanently, for the whole history of your account โ€” event retention does not apply to metrics. | General API rate limits apply as for all other endpoints. Every page is one request. --- ## ๐Ÿ›  Troubleshooting | What you see | Why | What to do | |---|---|---| | `"data": []` | Nothing matches: a typo in an ID, a time range without any sent email, or a filter value that does not exist. | Remove the filters one by one until data appear. | | A month or a day is missing | It has no sent email โ€” buckets without data are not returned. | Fill it with zeros on your side. | | The numbers are higher than yesterday | Counters grow as long as people open and click older emails. | Nothing โ€” re-read recent periods when you need current numbers. | | `context`, `conversions`, `links`, โ€ฆ are missing | Sections come only when you ask for them. | Add them to `include`. | | Open rate differs from another tool | Different sources counted. | Check `meta.interaction_sources`; bots are counted by default. | | `422 invalid-request` | A parameter is wrong. | Read `message` โ€” it names the parameter. | | `400 invalid-cursor`, or the same page again and again | A paging mistake. | See **Common mistakes** in **Reading all pages**. | --- ## ๐Ÿงพ Response format Standard API v3 envelope: `{"status": "ok", "meta": {"cursor", "has_more", "interaction_sources"}, "data": [bucket, โ€ฆ]}`. Without `group_by`, `dimensions` is `{}`. Errors: `{"status": "error", "meta": [], "message": "...", "type": "..."}` โ€” `type` is a machine-readable error code: ```json { "status": "error", "meta": [], "message": "include context requires group_by email_statistic_id", "type": "invalid-request" } ``` | `type` | Status | What to do | |---|---|---| | `invalid-request` | 422 | Fix the parameter named in `message` โ€” an unknown value of `group_by`, `include` or `interaction_sources`, a malformed ID, level or time, two `time:*` dimensions, an empty `interaction_sources`, or `include=context` without `group_by=email_statistic_id`. | | `invalid-cursor` | 400 | The cursor is malformed or belongs to different parameters โ€” start again from the first page. | | `unauthorized` | 401 | Wrong email or API key. | | `license-required` | 402 | The account has no valid license for API access. | | `account-not-found` | 400 | The account does not exist (or was archived). | | `rate-limited` | 429 | General API rate limit exceeded โ€” wait `Retry-After` seconds. | | `method-not-allowed` | 405 | Only `GET` is supported. | | `error` | other | Any other error โ€” see `message`. | Unexpected server errors (`500`) may come without `type`. New fields and sections may be added over time; ignore fields you don't know. Existing fields never change or disappear. --- ## ๐Ÿ” Migrating from `/email-performance-overview` Email metrics are its successor: the same filters and `group_by`, the same numbers (with the default `interaction_sources`) and nearly the same bucket โ€” plus paging, `include` and `interaction_sources`. | Before | With email metrics | |---|---| | All buckets in one response | Pages โ€” follow `meta.cursor` while `has_more` is `true`. | | `detail=brief` | No `include`. | | `detail=full` | `include=conversions,bounce_reasons,unsubscribe_reasons,clicked_urls,devices,email_clients,context` โ€” or only the sections you use. | | `opens.human` / `proxied` / `bot` / `total` | Flat `opens` (`unique`, `total`, rates) counting `interaction_sources`. Old `opens.total` = new `opens` with the default sources; the same for `clicks`. | | Dimensions (`links`, `device_types`, `operating_systems`, `user_agents`) without bots and proxies | They count `interaction_sources`. Old values = new with `interaction_sources=human`. | | `links` and `user_agents`: one top 10 over the whole request | Top 10 of each bucket. | | `meta.filter`, `meta.group_by`, `meta.total_buckets` | Not returned โ€” you know your parameters; count the buckets while reading the pages. | | Buckets without conversions in EUR | In the account's base currency. | ## Operations Parameters, request bodies and response examples: [email-metrics.json](https://app.smartemailing.cz/docs/api/v3/openapi/email-metrics.json) - `GET /email-statistics/metrics` โ€” Read email metrics # Event Streams โ€” SmartEmailing API v3 > Interactive documentation for people: https://app.smartemailing.cz/docs/api/v3/index.html#tag/event-streams Event streams deliver events of your account **in the order they were recorded, exactly from where you left off**. | Topic | Events | |---|---| | `email` | deliveries, opens, clicks, bounces, unsubscribes, spam complaints and conversions (orders attributed to an email) โ€” see **Email events** below | ## โšก Why event streams - **No more polling with time windows.** You don't track timestamps or offsets โ€” the server remembers your position. - **Nothing gets lost.** Every event is delivered until you confirm it. If your job crashes mid-batch, the next read returns the same batch again. - **No more daily full re-syncs.** Instead of downloading the whole history every night, you receive only what is new since your last read. ## ๐Ÿ”” Use event streams, not webhooks **Event streams are the reliable way to receive email events. We recommend replacing the `email_open`, `email_click`, `delivery_status` and `unsubscribed_contact` webhooks with them, and using them for every new integration.** These webhooks remain supported, but get no new features โ€” new capabilities come to event streams only. | Situation | Webhooks | Event streams | |---|---|---| | Your server is down overnight | Events are lost. After about 5 hours of failed retries the webhook is switched off. | Nothing is lost โ€” the stream waits where you stopped. | | A large campaign goes out | Each event is a separate request. Your server has to handle tens of thousands of them at once โ€” they wait in line, time out and are retried, so processing falls behind. | 5โ€“10 minutes, then a whole batch at once โ€” up to 10 000 events you can save in a single database write. | | One action, instant reaction | Seconds โ€” as long as your server keeps up. | 5โ€“10 minutes. The stream waits until every event recorded at the same moment is safely stored, so it never skips one. Streams are built for complete data, not for instant reactions. | | History | Only events after the webhook was created. | Up to 20 months back with `since`, and again with `reset`. | | What you have to run | A public HTTPS endpoint that is always up, a queue to absorb the peaks and a worker to process it. | Nothing extra โ€” a cron job or a serverless function that calls our API. Your stream is the queue. | Webhooks only make sense when a reaction within seconds matters more to you than complete data. --- ## ๐Ÿš€ Quick start **1. Create a stream** (once โ€” store the returned `id` in your configuration): ```bash curl -u "you@example.com:API_KEY" \ -X POST https://app.smartemailing.cz/api/v3/event-streams \ -H "Content-Type: application/json" \ -d '{"topic": "email", "label": "CRM sync", "include": ["contact", "automation", "template"]}' ``` `include` is optional โ€” it adds contact fields, the automation and the email template (subject, tracking parameters) to every event (see **Extra data (`include`)** below). To change it, create a new stream. ```json { "status": "created", "meta": [], "data": { "id": "5f1c0e7a9b2d4c3e8a6f1b0d2c4e6a8b", "topic": "email", "label": "CRM sync", "include": ["contact", "automation", "template"], "created_at": "2026-10-12T08:00:00Z", "last_read_at": "2026-10-12T08:00:00Z", "awaiting_ack": false } } ``` > โณ **Don't panic โ€” your first events arrive about 5 minutes after you create the stream.** > > A new stream (and a stream after `reset`) waits about 5 minutes before it delivers anything โ€” > even when you ask for history with `since`. Until then every read returns an empty batch > (`"data": []`) and `meta.retry_after` tells you how many seconds to wait. This short delay > guarantees that no event is ever skipped. **2. Read a batch:** ```bash STREAM_ID=5f1c0e7a9b2d4c3e8a6f1b0d2c4e6a8b curl -u "you@example.com:API_KEY" \ https://app.smartemailing.cz/api/v3/event-streams/$STREAM_ID ``` ```json { "status": "ok", "meta": { "cursor": "1.Qm9vS2V5LWJhdGNoLWN1cnNvci1leGFtcGxlLTAwMDAwMDAx", "has_more": true, "retry_after": null }, "data": [ { "specversion": "1.0", "id": "8f3c2a1b9d4e4f5a8b7c6d5e4f3a2b1c", "source": "/accounts/123456", "type": "email.opened", "time": "2026-10-12T07:59:02Z", "accountid": 123456, "data": { "email_message_id": "0199a1b2c3d47e8f9a0b1c2d3e4f5a6b", "email_statistic": { "id": "f7a60dec1b2c4d3e9f8a7b6c5d4e3f2a", "type": "newsletter", "name": "October newsletter", "legacy_campaign_id": 120, "template": { "subject": "October news for you", "tracking_parameters": [ {"key": "utm_source", "value": "newsletter"}, {"key": "utm_campaign", "value": "october"} ] }, "automation": null }, "contact": { "id": 135, "emailaddress": "jane@example.com", "name": "Jane", "surname": "Doe", "gender": "F", "nameday": "2000-07-26", "phone": null, "cellphone": "+420777123456" }, "details": { "ip_address": "203.0.113.7", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", "device_type": "desktop" } } } ] } ``` **3. Confirm the batch** with its `meta.cursor` after you have processed it: ```bash curl -u "you@example.com:API_KEY" \ -X POST https://app.smartemailing.cz/api/v3/event-streams/$STREAM_ID/ack \ -H "Content-Type: application/json" \ -d '{"cursor": "1.Qm9vS2V5LWJhdGNoLWN1cnNvci1leGFtcGxlLTAwMDAwMDAx"}' ``` Repeat steps 2 and 3. That's the whole integration. ### Complete consumer loop **PHP** (Guzzle): ```php $client = new GuzzleHttp\Client([ 'base_uri' => 'https://app.smartemailing.cz/api/v3/', 'auth' => ['you@example.com', 'API_KEY'], ]); $streamId = '5f1c0e7a9b2d4c3e8a6f1b0d2c4e6a8b'; while (true) { $response = $client->get("event-streams/{$streamId}"); $batch = json_decode((string) $response->getBody(), true); foreach ($batch['data'] as $event) { processEvent($event); // idempotent: deduplicate by $event['id'] } if ($batch['meta']['cursor'] !== null) { $client->post("event-streams/{$streamId}/ack", [ 'json' => ['cursor' => $batch['meta']['cursor']], ]); } if (!$batch['meta']['has_more']) { sleep($batch['meta']['retry_after']); } } ``` **Python** (requests): ```python import time, requests session = requests.Session() session.auth = ("you@example.com", "API_KEY") stream_id = "5f1c0e7a9b2d4c3e8a6f1b0d2c4e6a8b" base = f"https://app.smartemailing.cz/api/v3/event-streams/{stream_id}" while True: response = session.get(base) response.raise_for_status() batch = response.json() for event in batch["data"]: process_event(event) # idempotent: deduplicate by event["id"] cursor = batch["meta"]["cursor"] if cursor: session.post(f"{base}/ack", json={"cursor": cursor}).raise_for_status() if not batch["meta"]["has_more"]: time.sleep(batch["meta"]["retry_after"]) ``` --- ## ๐Ÿง  How it works | Term | Meaning | |---|---| | **Stream** | Your persistent position in the account's events of one topic. You can have several independent streams (CRM, data warehouse, โ€ฆ). | | **Batch** | What one `GET` returns โ€” up to `limit` events (default 1 000, max 10 000). | | **Cursor** | Opaque `meta.cursor` value identifying the end of the batch. Valid only for the stream it came from. | | **Ack** | `POST โ€ฆ/ack` with the cursor โ€” "I have processed everything up to here". The stream moves on. | | **Nack** | `POST โ€ฆ/nack` โ€” "give me this batch again", e.g. with a smaller `limit`. The stream stays where it is. | - **At-least-once delivery.** Until you acknowledge a batch, every `GET` returns **the same batch again** (regardless of `limit`). If your process crashes after reading, nothing is lost โ€” but you may see an event twice. Make processing idempotent and **deduplicate by the event `id`**. - **Order.** Events come in the order they were recorded, not by `time`. An `email.opened` may arrive before the `email.delivered` of the same message (delivery is recorded in batches) โ€” pair them by `data.email_message_id`. - **Freshness.** New events become readable roughly **5โ€“10 minutes** after they are recorded, and a new or reset stream delivers its first events about **5 minutes** after creation. Why the wait: events recorded at the same moment are not always stored in the order they were created. The stream moves on only when all of them are safely stored, so none is ever skipped. We keep this margin generous on purpose, so that nothing is skipped even when our servers are under heavy load โ€” complete data matter more than a few minutes. - **When you are caught up**, the response has `"has_more": false` and `retry_after` in `meta` (also sent as the `Retry-After` header) with the number of seconds after which new events may be available. Respect it โ€” polling more often returns empty batches. - **Empty batch** = `"data": []` and `"cursor": null` in `meta`; there is nothing to acknowledge. - **Streams do not expire.** A stream keeps its position until you delete it. - **No filter by event type โ€” on purpose.** A stream is meant to keep your own copy of the data complete. Store every event and answer questions like "who clicked in campaign X" from your own database โ€” that is faster and more flexible than asking a remote API over HTTP. Need only some types, e.g. bounces and unsubscribes for list hygiene? Skip the others in your loop. --- ## โช Starting from history and resets - Without `since`, a stream starts **now** โ€” it delivers events recorded from its creation on. - With `since` (e.g. `"since": "2026-01-01T00:00:00Z"`), it starts at the **first message sent from that time** and delivers everything recorded from there on โ€” the messages' deliveries, opens and clicks included. Use it for the initial load. The history starts arriving about 5 minutes after you create the stream. - `POST โ€ฆ/reset` (no body) moves the stream back to where it started when you created it and drops the unacknowledged batch โ€” the stream delivers all its events again. Use it after you lost the data you had processed. - `POST โ€ฆ/nack` (no body) drops the unacknowledged batch without moving the stream โ€” the next read returns the same events again, sized by your current `limit`. Free. - Want only new events and skip the backlog? Delete the stream and create a new one without `since`. - Starting from history (`since` on create) and **every reset** consume the **seek quota** (`nack` does not): 10 seeks, then one more every 14 days, per account and topic. It is meant for the initial load and rare recoveries, not for daily re-downloads โ€” keep your stream and keep reading it instead. Exhausted quota responds `429` with `Retry-After`. - Events are kept for **20 months** by default (your account may have a different retention agreed with us). Older events are not available, even with `since`. Totals and rates stay in [Email Metrics](https://app.smartemailing.cz/docs/api/v3/guides/email-metrics.md) permanently. --- ## ๐Ÿ“ Limits | Limit | Value | |---|---| | Streams per account | 10 โ€” delete unused streams (`DELETE /event-streams/{id}`) | | Events per batch | `limit` 1โ€“10 000, default 1 000 (higher values are capped) | | Seek quota (create with `since`, reset) | 10, then 1 per 14 days, per account and topic | | Freshness | ~5โ€“10 minutes; first events ~5 minutes after create or reset | General API rate limits apply as for all other endpoints. --- ## ๐Ÿงฉ Recipes - **Sync engagement into a CRM** โ€” one stream, a loop as above, upsert contact activity by `data.contact.id` / `data.contact.emailaddress`. - **Initial load + continuous sync** โ€” create the stream with `since` (e.g. 12 months back), then keep reading the same stream; it seamlessly continues with new events. - **More consumers** (CRM and a data warehouse) โ€” one stream per consumer. Never share one stream between independent consumers. - **Batch too big for your runtime** (timeout in a serverless function) โ€” choose a `limit` with margin; a smaller `limit` applies from the next batch on. If a batch is already waiting and is too big, call `POST โ€ฆ/nack` and read again with a smaller `limit` โ€” nothing is lost or skipped. - **Recovery after an outage** โ€” nothing to do: the stream waits at your last acknowledged position. --- ## ๐Ÿ“จ Email events (topic `email`) Every item of the batch's `data` is one email event โ€” something that happened to one message sent to one contact. Each event is a [CloudEvents 1.0](https://cloudevents.io) event in structured JSON format, so CloudEvents SDKs and tools can read it as is. All events share the same envelope; `type` tells what happened and `data.details` carries the type-specific details. ๐Ÿ“‹ **A full example of every event type** (and of an event with `include`) is in the response examples of [Read batch of events](https://app.smartemailing.cz/docs/api/v3/openapi/event-streams.json) (`GET /event-streams/{id}`). | Field | Description | |---|---| | `specversion` | CloudEvents version, always `1.0`. | | `id` | Unique event ID โ€” use it for deduplication. | | `source` | Account the event comes from, `/accounts/{account ID}`. | | `type` | One of the seven event types below. | | `time` | When the event happened (UTC, `YYYY-MM-DDTHH:MM:SSZ`). | | `accountid` | Account the event belongs to, as a number (CloudEvents extension attribute). | | `data.email_message_id` | ID of the individual message (one email to one contact) โ€” pair events of one message by it. | | `data.email_statistic.id` | ID of the email statistic the message belongs to โ€” one measured campaign, not this single message: a newsletter, one email node of an automation, an autoresponder, or one tag of custom or transactional emails. Same ID as `email_statistic_id` in [Email Metrics](https://app.smartemailing.cz/docs/api/v3/guides/email-metrics.md) โ€” use it to get the email's totals and rates. | | `data.email_statistic.type` | `newsletter`, `autoresponder`, `automation`, `trigger_action`, `custom_email`, `transactional_email` or `opt_in_email`; `null` (as well as `name`) when the statistic no longer exists. Newsletters are now sent by automations, but they keep the type `newsletter`; an automation email node marked as transactional comes as `transactional_email`. | | `data.email_statistic.name` | Name of the campaign or of the automation email (may be an empty string). | | `data.email_statistic.legacy_campaign_id` | Numeric ID of a legacy campaign (`newsletter`, `autoresponder`, `trigger_action`, `custom_email`, `transactional_email`) as used by `/campaign-stats-sent`; `null` for everything sent by an automation (including new newsletters), opt-in emails and campaigns that no longer exist. | | `data.contact` | `{id, emailaddress}` โ€” `emailaddress` is `null` for a deleted contact. | | `data.details` | Type-specific details (see each type), `{}` when there are none. | ### Extra data (`include`) When you create the stream with `include` (e.g. `"include": ["contact", "automation", "template"]`), every event carries extra fields. To change `include`, create a new stream. Included values are the state at the moment of reading, so a replayed event carries today's values. | `include` | Adds | |---|---| | `contact` | `data.contact.name`, `surname`, `gender`, `nameday`, `phone`, `cellphone` โ€” named as in the v3 contact, dates as `YYYY-MM-DD` (the year of `nameday` has no meaning); `null` for a deleted contact. The set of fields may grow. | | `automation` | `data.email_statistic.automation` โ€” `{id, name, node: {id, name}}` of the automation and email node that sent the email โ€” for every email sent by an automation, whatever its `type` (`automation`, a new `newsletter`, `transactional_email`); `null` for emails not sent by an automation. | | `template` | `data.email_statistic.template` โ€” `{subject, tracking_parameters}` of the email **as set in the campaign, before personalization** (personalization fields are not filled in; the values actually used in a click are in `details.link`). `tracking_parameters` is `[{key, value}]`, `[]` when there are none; for an email sent by an automation the node parameters override the email ones. `null` for `custom_email`, `transactional_email` and `opt_in_email` not sent by an automation, and for deleted campaigns. | ### `email.delivered` โ€” message delivered The recipient's mail server accepted the message. `time` is the moment of delivery. `details.mx_response` โ€” response of the recipient's mail server. ### `email.opened` โ€” message opened The contact opened the message (each open is a separate event). `details`: `ip_address`, `user_agent`, `device_type` (`desktop`, `mobile`, `tablet`, `unknown`, `proxied` โ€” a person behind a privacy proxy that hides the device, `bot` โ€” an automatic action such as a security scanner or a link checker). Privacy proxies such as Apple Mail Privacy Protection or Gmail image proxy can show up as either: sometimes they fetch the email on their own, sometimes only when a person opens it. We tell these apart for every single interaction, so the same proxy appears as `bot` or as `proxied`. Email Metrics use the same classification, so your numbers match. ### `email.clicked` โ€” link clicked The contact clicked a link in the message (each click is a separate event). `details`: `link`, `ip_address`, `user_agent`, `device_type`. ### `email.bounced` โ€” message not delivered The message could not be delivered. `details.bounce_type` โ€” `hard` (permanent, e.g. the address does not exist) or `soft` (temporary, e.g. a full mailbox). `details.reason` โ€” one of `email_does_not_exist`, `mailbox_full`, `flooded_mailbox`, `greylisted`, `deferred`, `mx_failure`, `relay_error`, `spam`, `spam_rate_limit`, `final_confirmation_timeout`, `suppressed`. ### `email.unsubscribed` โ€” contact unsubscribed The contact unsubscribed through this message. `details.reason` โ€” one of `too_frequent`, `not_relevant`, `content_abusive`, `unsolicited`, `list_unsubscribe` (one-click unsubscribe in the mail client), `unsubscribe_redirection`, `other`, `custom_reason`, `no_reason_given`; `details.custom_reason` โ€” the answer to the custom question of the unsubscribe page (`null` for older events); `details.comment` โ€” the contact's comment, if any. ### `email.spam_complained` โ€” marked as spam The contact marked the message as spam in their mail client (reported by the mailbox provider). No details. ### `email.converted` โ€” conversion attributed to the message The contact reached a conversion goal and we attributed it to this message โ€” the same conversions that Email Metrics count in `conversions`. Today the only goal is an order. One conversion is one event, attributed to one message: the message the contact clicked last before the order (or, without a click, opened last). The full rules with examples are in [How a conversion is attributed](https://app.smartemailing.cz/docs/api/v3/guides/email-metrics.md) in **Email Metrics**. An order brings **at most one** `email.converted` event โ€” when it first reaches SmartEmailing. Later changes of the order (status, cancellation, amount) send no further event and do not take the conversion back. An order without a click or open in the attribution window brings no event at all. `time` โ€” when the conversion reached SmartEmailing and was attributed, not when it happened; orders sent to us later arrive later. `details.category` โ€” which goal the contact reached: today always `order`. More categories may be added; each comes with its own object named after it (`details.order` for `order`). Skip events with a category you don't know. `details.attribution` โ€” `direct` (the contact clicked in this message at most 1 day before the order) or `assisted` (the click was 1โ€“5 days before the order, or the contact only opened the message at most 1 day before it). The order goes to the message with the latest click; only without a click to the one with the latest open. Clicks and opens of every source count, including those classified as `proxied` or `bot`. `details.order` โ€” the order: - `eshop_name`, `eshop_code` โ€” the e-shop and the order code within it, as sent with the order; together they identify the order (the same fields as in [Import orders](https://app.smartemailing.cz/docs/api/v3/openapi/e-commerce.json)). - `revenue`, `margin` โ€” each with two variants of `{without_vat, with_vat, currency}`: `in_order_currency` in the currency the order was paid in, `in_base_currency` converted to your account's base currency (rounded separately, so converted sums may differ by a minor unit). The margin is zero when the order was sent without it. New event types and new fields may be added over time; ignore types and fields you don't know. Existing fields never change or disappear. --- ## ๐Ÿงพ Response format Event streams use the standard API v3 envelope: - success: `{"status": "ok", "meta": {...}, "data": ...}` (`"created"` when a stream is created) โ€” a single stream or a list of streams in `data`; a batch has its events in `data` and `cursor`, `has_more`, `retry_after` in `meta`. An empty `meta` is `[]`, a filled one is an object; - `ack` and `DELETE` respond `204 No Content`; - errors: `{"status": "error", "meta": [], "message": "...", "type": "..."}` โ€” `type` is a machine-readable error code: ```json { "status": "error", "meta": [], "message": "Missing key: label", "type": "invalid-request" } ``` | `type` | Status | What to do | |---|---|---| | `invalid-request` | 422 | Fix the request (see `message`). | | `not-found` | 404 | The stream does not exist (or was deleted) โ€” create a new one. | | `limit-reached` | 422 | 10 streams already exist โ€” delete unused ones. | | `seek-limit-reached` | 429 | Seek quota exhausted โ€” wait `Retry-After` seconds, or keep reading your existing stream. | | `invalid-cursor` | 400 | The cursor is malformed or belongs to another stream. | | `batch-mismatch` | 409 | The cursor does not match the batch awaiting acknowledgement โ€” read the stream again and acknowledge the new cursor. | | `concurrent-modification` | 409 | Another request changed the stream at the same time โ€” retry. | | `save-failed` | 500 | Temporary failure โ€” retry. | | `invalid-json` | 422 | The request body is not valid JSON. | | `unauthorized` | 401 | Wrong email or API key. | | `license-required` | 402 | The account has no valid license for API access. | | `account-not-found` | 400 | The account does not exist (or was archived). | | `rate-limited` | 429 | General API rate limit exceeded โ€” wait `Retry-After` seconds. | | `method-not-allowed` | 405 | The HTTP method is not supported by this endpoint. | | `error` | other | Any other error โ€” see `message`. | Unexpected server errors (`500`) and unknown URLs (`404` outside a stream) may come without `type`. --- ## ๐Ÿ” Migrating from `/campaign-stats-sent` and `/email-statistic-events-jsonl` Event streams replace both endpoints. Their time windows, campaign filters, `sort` and offset paging were needed to find out *what changed* โ€” a stream gives you exactly that, so you don't need them anymore. | Before | With event streams | |---|---| | Polling `email-statistic-events-jsonl` with `interval_from = now โˆ’ 15 min` | Read your stream; it returns only new events. | | Re-downloading the same campaigns repeatedly | Read your stream and filter by `data.email_statistic.id` on your side. | | Daily full pass through `campaign-stats-sent` via `offset` | Read your stream continuously; create it once with `since` for history. | | One-off history of a campaign | Numbers only (opens, clicks, rates): **Email Metrics** with `email_statistic_ids=`. Individual events: query your own copy of the data โ€” if you don't have one yet, load it once with a stream created with `since` and keep reading it. | **`/email-statistic-events-jsonl` fields** | Before | Now | |---|---| | `type` (`opened`, โ€ฆ) | `type` (`email.opened`, โ€ฆ); `sent` is now `email.delivered` | | `contact.id`, `contact.email_address` | `data.contact.id`, `data.contact.emailaddress` | | `received_at` (local time) | `time` (UTC) | | `email_statistic.id` | `data.email_statistic.id` | | `details` | `data.details` | **`/campaign-stats-sent` fields** | Before | Now | |---|---| | `uid` | `data.email_message_id` | | `id` | not available โ€” use `data.email_message_id` | | campaign ID (`newsletter_id`, โ€ฆ) + `type` | `data.email_statistic.legacy_campaign_id`, `data.email_statistic.type` | | `contact_id`, `emailaddress` | `data.contact.id`, `data.contact.emailaddress` | | `time` | `time` of the `email.delivered` event | | `opened`, `clicked`, `unsubscribed`, `bounced` | an `email.opened` / `email.clicked` / `email.unsubscribed` / `email.bounced` event exists for the `data.email_message_id` | A message appears once it is delivered (`email.delivered`) or bounces (`email.bounced`). ## Operations Parameters, request bodies and response examples: [event-streams.json](https://app.smartemailing.cz/docs/api/v3/openapi/event-streams.json) - `GET /event-streams` โ€” List event streams - `POST /event-streams` โ€” Create event stream - `GET /event-streams/{id}` โ€” Read batch of events - `DELETE /event-streams/{id}` โ€” Delete event stream - `POST /event-streams/{id}/ack` โ€” Acknowledge batch - `POST /event-streams/{id}/nack` โ€” Release batch - `POST /event-streams/{id}/reset` โ€” Reset event stream # Webhooks โ€” SmartEmailing API v3 > Interactive documentation for people: https://app.smartemailing.cz/docs/api/v3/index.html#tag/webhooks Subscribe to event notifications โ€” opens, clicks, unsubscribes, bounces, and more. ## ๐Ÿ”” For email events, use Event Streams instead **We recommend [Event Streams](https://app.smartemailing.cz/docs/api/v3/guides/event-streams.md) for opens, clicks, deliveries and unsubscribes โ€” they are the reliable way to receive email events.** The `email_open`, `email_click`, `delivery_status` and `unsubscribed_contact` webhooks remain supported, but get no new features โ€” new capabilities come to event streams only. - **Nothing is lost when your server is down.** A webhook is retried for about 5 hours and then switched off; the events in between are gone. A stream waits where you stopped. - **No flood during large sends.** Instead of tens of thousands of separate requests at once, you read batches of up to 10 000 events at your own pace and save each in a single database write. - **No infrastructure to run.** No public endpoint, no queue to absorb the peaks, no worker โ€” a cron job or a serverless function is enough. Your stream is the queue. - **History included.** Load past events with `since` and read them again with `reset`. See [Use event streams, not webhooks](https://app.smartemailing.cz/docs/api/v3/guides/event-streams.md) for the full comparison. ## Operations Parameters, request bodies and response examples: [webhooks.json](https://app.smartemailing.cz/docs/api/v3/openapi/webhooks.json) - `GET /web-hooks` โ€” List webhooks - `POST /web-hooks` โ€” Create webhook - `DELETE /web-hooks/{id}` โ€” Delete webhook