Messaging

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

GET
POST
POST

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. Treat that 404 as queued and read again a few seconds later.

Required API key scopes

transactional_email:read

Path parameters

  • id
    string

Response


Example request

GET /api/projects/:project_id/messaging/emails/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/messaging/emails/:id/

Example response

Status 200
RESPONSE
{
"id": "string",
"status": "queued",
"created_at": "2019-08-24T14:15:22Z",
"status_at": "2019-08-24T14:15:22Z",
"reason": "string"
}
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 the email is queued but its first status isn't recorded 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:write

Request parameters

  • identifier
    string
  • all_marketing
    boolean
  • topics
    object

Response


Example request

POST /api/projects/:project_id/messaging/preferences
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/messaging/preferences/\
-d identifier="string"

Example response

Status 200
RESPONSE
{
"identifier": "string",
"all_marketing": true,
"topics": {
"property1": true,
"property2": true
}
}
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:write

Request parameters

  • to
    string
  • message_data
    object
  • template_id
    string
  • template_key
    string
  • distinct_id
    string | null
  • subject
    string
  • html
    string
  • text
    string
  • reply_to
    array
  • cc
  • bcc
  • attachments
    Click to open
    array | null
  • capture_engagement
    boolean
  • from
    string

Response


Example request

POST /api/projects/:project_id/messaging/send/email
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/messaging/send/email/\
-d to="string"

Example response

Status 202 Email queued
RESPONSE
{
"message_id": "string",
"replayed": true
}
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
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
Status 429 Rate limited, or the project is over its email quota
Status 503 The email pipeline did not confirm the send