REST API

With the REST API, you can use mailing for email templating even if most of your app is not written in TypeScript or JavaScript.

MethodPathDescriptionExample
GET, POST/api/renderrender a template with props to HTMLLink
GET/api/sendMailsend an email with props

Note: /api/render is publicly accessible by default. However, if process.env.REQUIRE_API_KEY is set then api/render will 401 unless a valid API key is included in the request. Read more about API keys

MethodPathDescriptionExample
GET/api/previewsreturns the list of previewsLink
GET/api/previews/[previewClass]/[previewFunction]returns the rendered previewLink

MethodPathDescription
GET/api/listsget all lists
POST/api/listscreate a new list
GET/api/lists/[listId]/membersget the members of a list
POST/api/lists/[listId]/membersadd a member to a list
GET/api/lists/[listId]/members/[memberId]get a list member's status
PATCH/api/lists/[listId]/members/[memberId]update a list member's status

Mailing uses API keys to protect endpoints that consume limited resources (e.g. sending email with your transport).

To get an API key, either set up a database and log in (recommended).

Or, make up your own key and assign it to the MAILING_API_KEY environment variable in your deployment environment.

You then pass your API key in each request with one of these methods:

  • Include the API key in the request headers: X-API-KEY=...
  • Include the API key as a query string parameter: ?apiKey=...