Messaging
For instructions on how to authenticate to use this endpoint, see API overview.
Endpoints
POST | |
GET | |
GET | |
POST | |
POST |
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
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 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.
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
- fromstring
Response
Example request
POST /api /projects /:project_id /messaging /send /email




