> For the complete documentation index, see [llms.txt](https://docs.mailtrap.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mailtrap.io/developers/promotional/email-campaigns.md).

# Email Campaigns

Manage email campaigns

## Get a list of email campaigns

> Returns a paginated list of the account's email campaigns, newest first.\
> \
> Pagination is page-token based. Use the \`token\` query parameter together with the\
> \`token\`, \`next\_token\`, and \`prev\_token\` values returned in the \`pagination\` object to\
> navigate between pages.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"token":{"name":"token","description":"Page number to retrieve (page-token pagination). Defaults to `1`.","in":"query","required":false,"schema":{"type":"integer","minimum":1,"default":1}},"per_page":{"name":"per_page","description":"Number of campaigns per page. Defaults to `50`, maximum `100`.","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100,"default":50}},"search":{"name":"search","description":"Filter campaigns by name (case-insensitive partial match).","in":"query","required":false,"schema":{"type":"string"}}},"responses":{"EmailCampaignsResponse":{"description":"A paginated list of email campaigns.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/EmailCampaign"}},"pagination":{"$ref":"#/components/schemas/Pagination"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"Pagination":{"type":"object","description":"Page-token pagination metadata.","properties":{"token":{"type":"integer","description":"Current page number."},"prev_token":{"type":["integer","null"],"description":"Previous page number, or `null` on the first page."},"next_token":{"type":["integer","null"],"description":"Next page number, or `null` on the last page."},"first_url":{"type":"string","format":"uri"},"prev_url":{"type":["string","null"],"format":"uri"},"current_url":{"type":"string","format":"uri"},"next_url":{"type":["string","null"],"format":"uri"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns":{"get":{"operationId":"getEmailCampaigns","summary":"Get a list of email campaigns","description":"Returns a paginated list of the account's email campaigns, newest first.\n\nPagination is page-token based. Use the `token` query parameter together with the\n`token`, `next_token`, and `prev_token` values returned in the `pagination` object to\nnavigate between pages.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/token"},{"$ref":"#/components/parameters/per_page"},{"$ref":"#/components/parameters/search"}],"responses":{"200":{"$ref":"#/components/responses/EmailCampaignsResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Create an email campaign

> Creates a new email campaign. The campaign must reference an existing sending domain via\
> \`mailsend\_domain\_id\`, and include a template \`subject\` within \`template\_attributes\`.\
> \
> Create accepts the same fields as update — pick the audience with\
> \`contact\_list\_ids\`/\`contact\_segment\_ids\`, set delivery options, and add the design via\
> \`template\_attributes.body\_html\`. The campaign is always created in the \`draft\` state;\
> scheduling and starting are separate actions (see the \`schedule\` and \`start\` endpoints).

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"schemas":{"EmailCampaignCreateRequest":{"description":"Campaign attributes. `name`, `mailsend_domain_id`, `from_local_part` and a template `subject` are required.","allOf":[{"$ref":"#/components/schemas/EmailCampaignWritableAttributes"},{"type":"object","required":["name","mailsend_domain_id","from_local_part","template_attributes"],"properties":{"template_attributes":{"type":"object","required":["subject"]}}}]},"EmailCampaignWritableAttributes":{"type":"object","description":"Campaign attributes. Both create and update accept the same fields. Create and update only\nmanage attributes and audience — the campaign always stays in `draft`; scheduling and\nstarting are performed via the dedicated lifecycle action endpoints.","properties":{"name":{"type":"string","description":"Campaign name."},"mailsend_domain_id":{"type":"string","format":"uuid","description":"UUID of the verified sending domain used for the campaign."},"from_display_name":{"type":"string","description":"Display name shown in the From header."},"from_local_part":{"type":"string","description":"Local part (before the @) of the From address."},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"template_attributes":{"$ref":"#/components/schemas/TemplateAttributes"},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"contact_list_ids":{"type":"array","description":"IDs of contact lists to send to. Treated as the full set of included lists — lists not\nlisted are removed. Combine with `contact_segment_ids` to target both.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of contact segments to send to. Treated as the full set of included segments.","items":{"type":"integer","format":"int64"}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"TemplateAttributes":{"type":"object","description":"Inline email template — the campaign's subject and design. Each campaign has exactly\none template, created together with it using the `template_attributes` fields.\nOn update, the campaign's template is always edited in place.\nUpdates are partial: only the sub-fields you provide change; sub-fields that\nare omitted or sent as `null` keep their current value.","properties":{"subject":{"type":"string","maxLength":255,"description":"Email subject line. Required when creating a campaign.\nSupports merge tags, e.g. `Hi {{first_name}}`."},"body_html":{"type":"string","maxLength":10000000,"description":"HTML body of the email (the design). Optional for a draft; required before the\ncampaign can be scheduled or started. Include an unsubscribe link via an anchor\nwhose `href` contains the `__unsubscribe_url__` placeholder — a design without one\nis accepted, but flagged with an \"Unsubscribe link is missing\" warning in the\nMailtrap UI. Supports `{{tag_name}}` merge tags."},"body_text":{"type":["string","null"],"maxLength":10000000,"description":"Optional plain-text alternative of the email body. Supports the same\n`__unsubscribe_url__` placeholder and `{{tag_name}}` merge tags as `body_html`."},"merge_tags":{"type":"array","description":"Bare names of the merge tags referenced in the subject/body, without the `{{ }}`\ndelimiters — e.g. `[\"first_name\"]` when the content contains `{{first_name}}`.\nLets Mailtrap track which contact fields the campaign uses. Replaced as a whole\nwhen provided; defaults to an empty array.","items":{"type":"string"}}}},"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"ValidationErrorResponse":{"type":"object","properties":{"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"VALIDATION_ERROR":{"description":"The request was rejected due to validation errors.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}}},"paths":{"/api/email_campaigns":{"post":{"operationId":"createEmailCampaign","summary":"Create an email campaign","description":"Creates a new email campaign. The campaign must reference an existing sending domain via\n`mailsend_domain_id`, and include a template `subject` within `template_attributes`.\n\nCreate accepts the same fields as update — pick the audience with\n`contact_list_ids`/`contact_segment_ids`, set delivery options, and add the design via\n`template_attributes.body_html`. The campaign is always created in the `draft` state;\nscheduling and starting are separate actions (see the `schedule` and `start` endpoints).","tags":["Email Campaigns"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailCampaignCreateRequest"}}}},"responses":{"201":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"422":{"$ref":"#/components/responses/VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Get an email campaign by ID

> Returns a single email campaign.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}":{"get":{"operationId":"getEmailCampaign","summary":"Get an email campaign by ID","description":"Returns a single email campaign.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Delete an email campaign

> Soft-deletes an email campaign. The campaign must not be in a sending state.\
> Returns \`204 No Content\` on success.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"responses":{"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"VALIDATION_ERROR":{"description":"The request was rejected due to validation errors.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ValidationErrorResponse":{"type":"object","properties":{"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}":{"delete":{"operationId":"deleteEmailCampaign","summary":"Delete an email campaign","description":"Soft-deletes an email campaign. The campaign must not be in a sending state.\nReturns `204 No Content` on success.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"responses":{"204":{"description":"The email campaign was deleted. No response body."},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Update an email campaign

> Updates an existing \`draft\` campaign. Only the provided attributes are changed. To edit the\
> template (subject or design), pass \`template\_attributes\` — the campaign's template is\
> always edited in place, and only the template sub-fields you provide change (see the\
> \`template\_attributes\` schema for the partial-update rules).\
> \
> Update accepts the same fields as create, including the audience\
> (\`contact\_list\_ids\`/\`contact\_segment\_ids\`). The typical flow is to create a draft, add its\
> design and audience over one or more updates, then schedule or start it via the dedicated\
> \`schedule\`/\`start\` action endpoints.\
> \
> Only \`draft\` campaigns can be updated — editing a campaign that is already scheduled/sending\
> returns \`422\`.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"schemas":{"EmailCampaignUpdateRequest":{"description":"Attributes to update. All fields optional; only provided fields change.","allOf":[{"$ref":"#/components/schemas/EmailCampaignWritableAttributes"}]},"EmailCampaignWritableAttributes":{"type":"object","description":"Campaign attributes. Both create and update accept the same fields. Create and update only\nmanage attributes and audience — the campaign always stays in `draft`; scheduling and\nstarting are performed via the dedicated lifecycle action endpoints.","properties":{"name":{"type":"string","description":"Campaign name."},"mailsend_domain_id":{"type":"string","format":"uuid","description":"UUID of the verified sending domain used for the campaign."},"from_display_name":{"type":"string","description":"Display name shown in the From header."},"from_local_part":{"type":"string","description":"Local part (before the @) of the From address."},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"template_attributes":{"$ref":"#/components/schemas/TemplateAttributes"},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"contact_list_ids":{"type":"array","description":"IDs of contact lists to send to. Treated as the full set of included lists — lists not\nlisted are removed. Combine with `contact_segment_ids` to target both.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of contact segments to send to. Treated as the full set of included segments.","items":{"type":"integer","format":"int64"}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"TemplateAttributes":{"type":"object","description":"Inline email template — the campaign's subject and design. Each campaign has exactly\none template, created together with it using the `template_attributes` fields.\nOn update, the campaign's template is always edited in place.\nUpdates are partial: only the sub-fields you provide change; sub-fields that\nare omitted or sent as `null` keep their current value.","properties":{"subject":{"type":"string","maxLength":255,"description":"Email subject line. Required when creating a campaign.\nSupports merge tags, e.g. `Hi {{first_name}}`."},"body_html":{"type":"string","maxLength":10000000,"description":"HTML body of the email (the design). Optional for a draft; required before the\ncampaign can be scheduled or started. Include an unsubscribe link via an anchor\nwhose `href` contains the `__unsubscribe_url__` placeholder — a design without one\nis accepted, but flagged with an \"Unsubscribe link is missing\" warning in the\nMailtrap UI. Supports `{{tag_name}}` merge tags."},"body_text":{"type":["string","null"],"maxLength":10000000,"description":"Optional plain-text alternative of the email body. Supports the same\n`__unsubscribe_url__` placeholder and `{{tag_name}}` merge tags as `body_html`."},"merge_tags":{"type":"array","description":"Bare names of the merge tags referenced in the subject/body, without the `{{ }}`\ndelimiters — e.g. `[\"first_name\"]` when the content contains `{{first_name}}`.\nLets Mailtrap track which contact fields the campaign uses. Replaced as a whole\nwhen provided; defaults to an empty array.","items":{"type":"string"}}}},"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ValidationErrorResponse":{"type":"object","properties":{"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"VALIDATION_ERROR":{"description":"The request was rejected due to validation errors.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}":{"patch":{"operationId":"updateEmailCampaign","summary":"Update an email campaign","description":"Updates an existing `draft` campaign. Only the provided attributes are changed. To edit the\ntemplate (subject or design), pass `template_attributes` — the campaign's template is\nalways edited in place, and only the template sub-fields you provide change (see the\n`template_attributes` schema for the partial-update rules).\n\nUpdate accepts the same fields as create, including the audience\n(`contact_list_ids`/`contact_segment_ids`). The typical flow is to create a draft, add its\ndesign and audience over one or more updates, then schedule or start it via the dedicated\n`schedule`/`start` action endpoints.\n\nOnly `draft` campaigns can be updated — editing a campaign that is already scheduled/sending\nreturns `422`.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailCampaignUpdateRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Start an email campaign

> Starts sending a \`draft\` campaign immediately. Runs full sending validation (the template\
> must have a \`body\_html\` design, the audience and verified sending domain must be set,\
> billing within limits); on failure the request returns \`422\` and the campaign stays a\
> \`draft\`. The campaign must be in the \`draft\` state — starting from any other state returns\
> \`422\`.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"ACTION_VALIDATION_ERROR":{"description":"The lifecycle action was rejected — the campaign was in a state that does not allow the\naction, the `datetime` was invalid, or sending validation failed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ActionValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ActionValidationErrorResponse":{"type":"object","description":"Validation error returned by the lifecycle action endpoints. `errors` is either a single\nmessage (an invalid state transition or an invalid `datetime`) or a list of messages\n(sending-validation failures).","properties":{"errors":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}/start":{"post":{"operationId":"startEmailCampaign","summary":"Start an email campaign","description":"Starts sending a `draft` campaign immediately. Runs full sending validation (the template\nmust have a `body_html` design, the audience and verified sending domain must be set,\nbilling within limits); on failure the request returns `422` and the campaign stays a\n`draft`. The campaign must be in the `draft` state — starting from any other state returns\n`422`.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/ACTION_VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Schedule an email campaign

> Schedules a \`draft\` campaign to start sending at a future time. Runs full sending validation\
> (the template must have a \`body\_html\` design, the audience and verified sending domain must\
> be set, billing within limits); on failure the request returns \`422\` and the campaign stays\
> a \`draft\`. The campaign must be in the \`draft\` state — scheduling from any other state\
> returns \`422\`. After scheduling, the time is reported back in\
> \`current\_state\_metadata.scheduled\_at\`.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"schemas":{"EmailCampaignScheduleRequest":{"type":"object","description":"When to start sending the campaign.","required":["datetime"],"properties":{"datetime":{"type":"string","format":"date-time","description":"When to send the campaign (ISO 8601). Must be in the future and no more than 1 month\nahead, otherwise the request is rejected with `422`."}}},"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ActionValidationErrorResponse":{"type":"object","description":"Validation error returned by the lifecycle action endpoints. `errors` is either a single\nmessage (an invalid state transition or an invalid `datetime`) or a list of messages\n(sending-validation failures).","properties":{"errors":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"ACTION_VALIDATION_ERROR":{"description":"The lifecycle action was rejected — the campaign was in a state that does not allow the\naction, the `datetime` was invalid, or sending validation failed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ActionValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}/schedule":{"post":{"operationId":"scheduleEmailCampaign","summary":"Schedule an email campaign","description":"Schedules a `draft` campaign to start sending at a future time. Runs full sending validation\n(the template must have a `body_html` design, the audience and verified sending domain must\nbe set, billing within limits); on failure the request returns `422` and the campaign stays\na `draft`. The campaign must be in the `draft` state — scheduling from any other state\nreturns `422`. After scheduling, the time is reported back in\n`current_state_metadata.scheduled_at`.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailCampaignScheduleRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/ACTION_VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Cancel a scheduled email campaign

> Cancels a scheduled campaign, removing the pending send job and returning the campaign to\
> the \`draft\` state. The campaign must be in the \`scheduled\` state — cancelling from any other\
> state returns \`422\` (\`"Campaign is not scheduled"\`).

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"ACTION_VALIDATION_ERROR":{"description":"The lifecycle action was rejected — the campaign was in a state that does not allow the\naction, the `datetime` was invalid, or sending validation failed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ActionValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ActionValidationErrorResponse":{"type":"object","description":"Validation error returned by the lifecycle action endpoints. `errors` is either a single\nmessage (an invalid state transition or an invalid `datetime`) or a list of messages\n(sending-validation failures).","properties":{"errors":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}/cancel":{"post":{"operationId":"cancelEmailCampaign","summary":"Cancel a scheduled email campaign","description":"Cancels a scheduled campaign, removing the pending send job and returning the campaign to\nthe `draft` state. The campaign must be in the `scheduled` state — cancelling from any other\nstate returns `422` (`\"Campaign is not scheduled\"`).","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/ACTION_VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Terminate a sending email campaign

> Terminates a campaign that is currently sending, aborting the in-flight send. The campaign\
> must be in a sending state (\`started\`, \`queued\`, or \`paused\`) — terminating from any other\
> state returns \`422\`.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"ACTION_VALIDATION_ERROR":{"description":"The lifecycle action was rejected — the campaign was in a state that does not allow the\naction, the `datetime` was invalid, or sending validation failed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ActionValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ActionValidationErrorResponse":{"type":"object","description":"Validation error returned by the lifecycle action endpoints. `errors` is either a single\nmessage (an invalid state transition or an invalid `datetime`) or a list of messages\n(sending-validation failures).","properties":{"errors":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}/terminate":{"post":{"operationId":"terminateEmailCampaign","summary":"Terminate a sending email campaign","description":"Terminates a campaign that is currently sending, aborting the in-flight send. The campaign\nmust be in a sending state (`started`, `queued`, or `paused`) — terminating from any other\nstate returns `422`.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/ACTION_VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```

## Reset an email campaign to draft

> Resets a campaign back to the \`draft\` state. Allowed only from the \`scheduled\` state;\
> resetting from any other state (e.g. a sending or terminal state) returns \`422\`.

```json
{"openapi":"3.1.0","info":{"title":"Email Campaigns","version":"2.0.0"},"tags":[{"name":"Email Campaigns","description":"Manage email campaigns"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","description":"Pass the API token as a Bearer token in the Authorization header","scheme":"bearer"}},"parameters":{"email_campaign_id":{"name":"email_campaign_id","description":"Unique identifier of the email campaign","in":"path","required":true,"schema":{"type":"integer","format":"int64","minimum":1}}},"responses":{"EmailCampaignResponse":{"description":"A single email campaign.","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/EmailCampaign"}}}}}},"UNAUTHENTICATED":{"description":"Authentication failed — missing or invalid API token.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"The API token does not have permission to access this resource.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionDeniedResponse"}}}},"NOT_FOUND":{"description":"The requested email campaign was not found.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}},"ACTION_VALIDATION_ERROR":{"description":"The lifecycle action was rejected — the campaign was in a state that does not allow the\naction, the `datetime` was invalid, or sending validation failed.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ActionValidationErrorResponse"}}}},"RATE_LIMITED":{"description":"Too many requests. The public API is rate limited to 150 requests per 10 seconds per\nAPI token. Retry after the window resets (see the `x-ratelimit-reset` header).","headers":{},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"schemas":{"EmailCampaign":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"type":{"type":"string","description":"Resource type discriminator. `ContactsEmailCampaign` targets contact lists/segments;\n`RecipientsEmailCampaign` targets an uploaded recipients list.","enum":["ContactsEmailCampaign","RecipientsEmailCampaign"]},"mailsend_domain_id":{"type":"string","format":"uuid"},"mailsend_domain_name":{"type":"string"},"name":{"type":"string"},"from_local_part":{"type":"string"},"from_display_name":{"type":"string"},"reply_to":{"$ref":"#/components/schemas/ReplyTo"},"current_state":{"type":"string","description":"Current state of the campaign in its lifecycle.","enum":["draft","scheduled","started","queued","paused","terminating","under_review","finished","failed","failed_immediately"]},"current_state_metadata":{"type":"object","description":"Metadata about the most recent state transition. Which keys are present depends on the state.","properties":{"reason":{"type":"string"},"error":{"type":"string","description":"Last error message recorded for a failed campaign."},"errors":{"type":"array","description":"Per-recipient errors recorded when sending failed.","items":{"type":"object","properties":{"message":{"type":"string"},"rcpt_index":{"type":"integer"}}}},"scheduled_at":{"type":"string","format":"date-time","description":"When the campaign is scheduled to send (ISO 8601). Present in the `scheduled` state."}}},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"},"last_started_at":{"type":["string","null"],"format":"date-time"},"last_started_at_date":{"type":"string","format":"date","description":"Date the campaign was last started. Present only when the campaign has been started."},"recipient_total_count":{"type":["integer","null"],"description":"Total number of recipients targeted by the campaign. `null` until the audience is resolved."},"contact_list_ids":{"type":"array","description":"IDs of the contact lists included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"contact_segment_ids":{"type":"array","description":"IDs of the contact segments included in the campaign's audience.","items":{"type":"integer","format":"int64"}},"delivery_mode":{"type":"string","description":"How the campaign is delivered. `rapid` sends as fast as possible; `gradual` throttles\nsending to `delivery_options.emails_per_hour`.","enum":["rapid","gradual"]},"delivery_options":{"type":"object","description":"Delivery throttling options. Applies when `delivery_mode` is `gradual`.","properties":{"emails_per_hour":{"type":["integer","null"]}}},"template":{"type":"object","description":"The campaign's template. `body_html` and `body_text` are returned only on\nsingle-campaign responses (create, update, get-by-ID); the list endpoint omits them to\nkeep the payload small.","properties":{"id":{"type":"integer","format":"int64"},"subject":{"type":"string"},"merge_tags":{"type":"array","items":{"type":"string"}},"body_html":{"type":["string","null"],"description":"HTML body (the design). Returned only on single-campaign responses."},"body_text":{"type":["string","null"],"description":"Plain-text body. Returned only on single-campaign responses."}}}}},"ReplyTo":{"type":"object","description":"Reply-To address parts.","properties":{"display_name":{"type":"string"},"local_part":{"type":"string"},"domain":{"type":"string"}}},"UnauthenticatedResponse":{"type":"object","properties":{"error":{"type":"string"}}},"PermissionDeniedResponse":{"type":"object","properties":{"errors":{"type":"string"}}},"NotFoundResponse":{"type":"object","properties":{"error":{"type":"string"}}},"ActionValidationErrorResponse":{"type":"object","description":"Validation error returned by the lifecycle action endpoints. `errors` is either a single\nmessage (an invalid state transition or an invalid `datetime`) or a list of messages\n(sending-validation failures).","properties":{"errors":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"RateLimitedResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/email_campaigns/{email_campaign_id}/reset":{"post":{"operationId":"resetEmailCampaign","summary":"Reset an email campaign to draft","description":"Resets a campaign back to the `draft` state. Allowed only from the `scheduled` state;\nresetting from any other state (e.g. a sending or terminal state) returns `422`.","tags":["Email Campaigns"],"parameters":[{"$ref":"#/components/parameters/email_campaign_id"}],"responses":{"200":{"$ref":"#/components/responses/EmailCampaignResponse"},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"},"422":{"$ref":"#/components/responses/ACTION_VALIDATION_ERROR"},"429":{"$ref":"#/components/responses/RATE_LIMITED"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mailtrap.io/developers/promotional/email-campaigns.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
