Transactional email
For instructions on how to authenticate to use this endpoint, see API overview.
Endpoints
POST | |
GET | |
GET | |
POST | |
POST | |
GET | |
GET | |
PATCH | |
GET |
Create messaging send email
Send one transactional email to one recipient. Name a template made transactional in template_id, and message_data fills its {{ variables.* }} placeholders. Or send content your code rendered with a template_key, a subject and html or text: PostHog sends it as is, and its metrics and run history group under the key. Transactional emails skip opt-outs and frequency caps. Send an Idempotency-Key header to retry safely without sending the email twice. Needs the transactional_email:write scope. A key with hog_flow:write also works, but that scope reaches the rest of Workflows too.
Required API key scopes
transactional_email:writeRequest parameters
- tostring
- message_dataobject
- template_idstring
- template_keystring
- distinct_idstring | null
- subjectstring
- htmlstring
- textstring
- reply_toarray
- cc
- bcc
- attachmentsarray | null
- capture_engagementboolean
- tracking
- scheduled_atstring | null
- sensitiveboolean
- categorystring
- fromstring
Response
Example request
POST /api /projects /:project_id /messaging /send /emailExample response
Status 202 Email queued
Status 400 A field is invalid, the template isn't transactional or its email is paused, the sender isn't verified, the recipient can't be used, the Idempotency-Key is invalid, the email is too large to send, or the project has reached its limit of template keys and the `template_key` is new. When a code send from a project with no verified sending domain would go out from the PostHog test sender, that sender refuses `cc`, `bcc` and `attachments`
Status 403 The project has no verified sending domain, and the PostHog test sender isn't available for its organization
Status 404 Template not found
Status 409 A request with the same Idempotency-Key is still in progress
Status 422 The email can't go out: the recipient is suppressed or can't receive email, sending is suspended for the project or paused for this transactional email, or the Idempotency-Key was already used for a different request, or the email would go out from the PostHog test sender to someone outside the organization
Status 429 Rate limited, or the project is over its email quota
Status 503 The email pipeline did not confirm the send
Retrieve messaging emails
Get the status of one transactional email by the message_id that the send returned, for 30 days after the send. Needs a project secret API key with the transactional_email:read scope. A key with hog_flow:read also works, but that scope reaches the rest of Workflows too. The first status is recorded a few seconds after the send, so a read right after a send can answer 404. That 404 doesn't say whether the email went out yet, so read again a few seconds later.
Required API key scopes
transactional_email:readPath parameters
- idstring
Response
Example request
GET /api /projects /:project_id /messaging /emails /:idExample response
Status 200
Status 401 The request has no project secret API key.
Status 404 No email of this project has this ID, or it is older than 30 days. In the first seconds after a send, it means PostHog accepted the email but hasn't recorded its first status yet.
Retrieve messaging emails status
Get the status of one transactional email by its message_id, or by the idempotency_key it was sent with when the send's response was lost. Name exactly one of them. A key gives the latest send with it that PostHog has a status for. Compare the response's created_at with when you sent: an earlier time means an earlier send with the same key, not the one whose response was lost. It answers like the read by message_id, for 30 days after the send, and needs the same transactional_email:read scope. A 404 doesn't mean the email wasn't sent: its first status can take a few seconds to arrive. To make sure it goes out, send it again with the same key within 24 hours.
Required API key scopes
transactional_email:readQuery parameters
- idempotency_keystring
- message_idstring
Response
Example request
GET /api /projects /:project_id /messaging /emails /statusExample response
Status 200
Status 400 The request names neither or both of `message_id` and `idempotency_key`, names one of them twice, or gives one in the wrong format: a `message_id` that isn't a UUID, or an `idempotency_key` that isn't 1 to 255 visible ASCII characters.
Status 401 The request has no project secret API key.
Status 404 No email of this project has this ID or key, or it is older than 30 days. In the first seconds after a send, it means PostHog accepted the email but hasn't recorded its first status yet.
Create messaging attachments uploads
Before sending an email with files, ask where to upload each one. Name each file by the SHA-256 of its bytes and its size. A file this project already uploaded answers present and needs no upload. Any other file answers upload: PUT its bytes to url with exactly the headers given and without your PostHog API key, before url_expires_at. Once every upload succeeded, send the email with the files' hashes in attachments. Needs the transactional_email:write scope.
Required API key scopes
transactional_email:writeRequest parameters
- filesarray
Response
Example request
POST /api /projects /:project_id /messaging /attachments /uploadsExample response
Status 200 Each file is present, or comes with where to upload it
Status 400 A file is malformed, there are more than 10, they're too large for one email, or the project can't send files yet
Status 429 Rate limited, or the project uploaded its daily limit of file bytes
Status 503 File storage didn't answer. Send the same request again
Create messaging preferences
Opt one recipient out of topics, or back in, in one call. all_marketing applies first, then each topic in order, and the whole change is saved at once. The same change twice ends the same, but a retry that lands after a newer change undoes that change. Workflows sends skip a marketing topic the recipient opted out of. Needs a project secret API key with the messaging_preference:write scope, which cannot send email. A key with hog_flow:write also works, but that scope can send transactional email too.
Required API key scopes
messaging_preference:writeRequest parameters
- identifierstring
- all_marketingboolean
- topicsobject
Response
Example request
POST /api /projects /:project_id /messaging /preferencesExample response
Status 200
Status 401 The request has no project secret API key.
Status 404 A topic key names no topic of this project, with the code `unknown_topic`. Nothing changed.
List all transactional code emails
List the emails your code sends under a template_key that no template owns, newest first.
Required API key scopes
hog_flow:readExample request
GET /api /projects /:project_id /transactional_code_emailsExample response
Status 200
Retrieve transactional code emails
Required API key scopes
hog_flow:readPath parameters
- idstring
Response
Example request
GET /api /projects /:project_id /transactional_code_emails /:idExample response
Status 200
Status 404 No such code email in this project.
Update transactional code emails
Change the description, the tags or the linked source file. The content always comes from your code, so it can't change here.
Required API key scopes
hog_flow:writePath parameters
- idstring
Request parameters
- descriptionstring
- tagsarray
- source_url
Response
Example request
PATCH /api /projects /:project_id /transactional_code_emails /:idExample response
Status 200
Status 403 You need editor access to this email's workflow.
Status 404 No such code email in this project.
Retrieve transactional code emails source candidates
Search the project's connected GitHub repositories for files that use this email's key, so you can pick one to link as its source file.
Required API key scopes
hog_flow:writeintegration:readPath parameters
- idstring
Response
Example request
GET /api /projects /:project_id /transactional_code_emails /:id /source_candidates




