Skip to the page

Broadcasts and audiences

A broadcast is one email for a whole audience. Each person gets their own copy, with their name, what you know about them and their own unsubscribe link.

Make an audience

An audience is a group of contacts. A broadcast goes to one audience, and a contact can be in many.

curl -X POST "$OPENSEND_API_URL/v1/audiences" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "name": "Beta testers"}'

Add contacts

A contact is a person of the workspace: an address, with a first and last name when you know them. The workspace holds an address once, so a second contact with it is refused with contact_taken. Name the audiences to put a new contact in with audienceIds.

curl -X POST "$OPENSEND_API_URL/v1/contacts" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "email": "grace@example.com",  "firstName": "Grace",  "audienceIds": [    "aud_01"  ]}'

Someone who is a contact already joins another audience with one call, by id or by address. Taking them out of an audience leaves them a contact.

curl -X POST "$OPENSEND_API_URL/v1/audiences/aud_02/contacts/ada%40example.com" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{}'

A contact is subscribed or unsubscribed, in every audience at once. Only subscribed contacts get a broadcast. A plan allows a number of contacts, counted once each however many audiences they are in, and one more is refused with contact_limit.

curl "$OPENSEND_API_URL/v1/contacts/ada%40example.com" \  -H "Authorization: Bearer $OPENSEND_API_KEY"

What you know about a contact

A contact holds properties: values of your own by name, such as a plan. Give a property a type and a fallback and it is checked from then on: a value of another type is refused, and {{plan}} in a broadcast is filled with the value of each contact, or with the fallback for a contact who has none.

curl -X POST "$OPENSEND_API_URL/v1/contact-properties" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "key": "company",  "type": "string",  "fallback": "your company"}'

A key you never defined still works: it takes any value and has no fallback.

Let readers choose

A topic is a kind of mail a reader can say yes or no to, such as product news. defaultSubscription says what holds for someone who never chose: opt_in, they get it, or opt_out, they only get it after they say yes.

curl -X POST "$OPENSEND_API_URL/v1/topics" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "name": "Product news",  "description": "What we shipped, once a month."}'

Give a broadcast a topicId and it only reaches the subscribed contacts of its audience who get that topic. Its unsubscribe link then takes a reader out of the topic and not out of everything, and the page behind the link lists the topics with a tick each. What one contact chose is topics on the contact.

curl -X PATCH "$OPENSEND_API_URL/v1/contacts/ada%40example.com" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "status": "unsubscribed"}'

Write the broadcast

A broadcast starts as a draft: a name, an audience, a sender, a subject and a body, and a reply address when replies should not go to the sender. A broadcast with no reply address of its own gets the default of the workspace. Nothing is sent until you send it.

curl -X POST "$OPENSEND_API_URL/v1/broadcasts" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "name": "December product update",  "audienceId": "aud_01",  "subject": "What is new"}'

These variables are filled in for each contact.

Variable
{{first_name}}
Filled with
The first name of the contact.
Variable
{{last_name}}
Filled with
The last name of the contact.
Variable
{{email}}
Filled with
The address of the contact.
Variable
{{unsubscribe_url}}
Filled with
The unsubscribe link of this contact.
Variable
{{plan}}
Filled with
A property of the contact, or its fallback.

What a contact wrote is escaped before it goes into the HTML. When the body has no {{unsubscribe_url}}, an unsubscribe link is added at the end.

A draft or a scheduled broadcast can still be changed.

curl -X PATCH "$OPENSEND_API_URL/v1/broadcasts/bc_05" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "subject": "What is new in December"}'

Build it from blocks

A broadcast does not have to be written as HTML. Give design in place of html and text, and both are made from it, with markup that mail apps accept. It is the design a template takes: a body of blocks, a style for the whole message, a preview and the fonts it loads. Templates shows one and lists the blocks.

  • The variables of a broadcast stand anywhere in the text of a block. In href and src a variable has to be the whole value.
  • For an unsubscribe link of your own, give a Link or a Button the href {{unsubscribe_url}}. Without one, a link is added at the end of the message.
  • html and text belong to the design from then on. Sending one of them to a broadcast built from blocks is refused with broadcast_designed. Send design again to change it, or design: null to turn it into a broadcast written as HTML, which keeps the HTML and the plain text it has.
  • A design with no blocks is not sent: broadcasts.send answers email_no_body.

Try it first

A test sends the draft to addresses you give, with "[Test]" before the subject, and leaves the broadcast as it is. An address that is a contact of the audience gets its own name and unsubscribe link, and any other gets the message with the names empty. The draft needs a sender, a subject and a message.

curl -X POST "$OPENSEND_API_URL/v1/broadcasts/bc_05/test" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{  "to": "you@example.com"}'

A copy of a broadcast is a new draft with the same audience, sender, subject and message. It works on one that was already sent, which is how you send it again.

curl -X POST "$OPENSEND_API_URL/v1/broadcasts/bc_04/duplicate" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{}'

Send it

Send the broadcast now, or give scheduledAt to start at a later time. It goes to everyone who is subscribed at that moment.

curl -X POST "$OPENSEND_API_URL/v1/broadcasts/bc_05/send" \  -H "Authorization: Bearer $OPENSEND_API_KEY" \  -H "Content-Type: application/json" \  -d '{}'
  • A large broadcast goes out in parts. Its status is sending until the last part is out, then sent.
  • recipients is how many people it is for, delivered how many copies were delivered, and failed how many the platform refused.
  • email_no_subject and email_no_body: the broadcast has no subject yet, or no message.
  • broadcast_empty: nobody is subscribed to the audience.
  • broadcast_sent: it has already been sent, so it cannot be sent or changed again.

Unsubscribing

The unsubscribe link opens a page of yours on the API, where the reader confirms. The contact then becomes unsubscribed and gets no more broadcasts.

The page takes its title, message, button and accent colour from the workspace. Change them with unsubscribePage.

curl "$OPENSEND_API_URL/v1/workspace" \  -H "Authorization: Bearer $OPENSEND_API_KEY"