APIs & Integrations

karien
Participant

build marketing email via api. - Table with tokens (fields)

is it possible to build a marketing email via API with a table and fields. 

4 Replies 4
GRajput
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

build marketing email via api. - Table with tokens (fields)

Hi @karien 

Yes, it is possible to build a marketing email via API with a table and fields. Here are the steps involved:

1. **Create a new marketing email.** To do this, you will need to make a POST request to the `/marketing/v1/emails` endpoint. The request body must be a JSON-formatted object with the following properties:
* `name`: The name of the marketing email.
* `subject`: The subject line of the marketing email.
* `content`: The content of the marketing email. This can be a plain text or HTML string.
* `template`: The ID of a marketing email template that you want to use. If you do not specify a template, the marketing email will be sent as plain text.

2. **Add a table to the marketing email.** To do this, you will need to make a POST request to the `/marketing/v1/emails/tables` endpoint. The request body must be a JSON-formatted object with the following properties:
* `name`: The name of the table.
* `columns`: An array of objects that define the columns in the table. Each object must have the following properties:
* `name`: The name of the column.
* `type`: The type of the column. Valid values are `text`, `number`, `date`, and `time`.
* `isRequired`: Whether or not the column is required.

3. **Add fields to the table.** To do this, you will need to make a POST request to the `/marketing/v1/emails/tables/fields` endpoint. The request body must be a JSON-formatted object with the following properties:
* `name`: The name of the field.
* `column`: The ID of the column that the field belongs to.
* `value`: The value of the field.

4. **Send the marketing email.** To do this, you will need to make a POST request to the `/marketing/v1/emails/send` endpoint. The request body must be a JSON-formatted object with the following properties:
* `email`: The email address of the recipient.
* `table`: The ID of the table that contains the data for the marketing email.

Here is an example of a JSON request body that you can use to build a marketing email with a table and fields:

```
{
"name": "My first marketing email",
"subject": "Welcome!",
"content": "<p>Welcome to our company!</p><p>Here is a table of some of our products:</p>",
"template": null,
"tables": [
{
"name": "Products",
"columns": [
{
"name": "Product Name",
"type": "text",
"isRequired": true
},
{
"name": "Price",
"type": "number",
"isRequired": true
},
{
"name": "Quantity",
"type": "number",
"isRequired": false
}
]
}
],
"fields": [
{
"name": "Product Name",
"column": 1,
"value": "Product 1"
},
{
"name": "Price",
"column": 2,
"value": 100
},
{
"name": "Quantity",
"column": 3,
"value": 1
}
]
}
```

This request will create a marketing email with a table that contains two columns: Product Name and Price. The email will be sent to the specified email address and will include the data for the table.

 

Hope this will helps you out. Please mark it as Solution Accepted to help other Community member.

Thanks!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


0 Upvotes
karien
Participant

build marketing email via api. - Table with tokens (fields)

Thank you Gaurav, for taking the time to give me all this info. Really appreciate it. 

GRajput
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

build marketing email via api. - Table with tokens (fields)

Hi @karien 

Please mark it as Solution Accepted and upvote to help other Community member.

 

Thanks!




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

build marketing email via api. - Table with tokens (fields)

Hey, @karien 👋 The Marketing Email endpoint can set the content of a marketing email but not create complex element like tables.

 

You'll need to create your custom modules and tables and save them as a custom email template to be used with emails you start via the API. 

 

Have fun building! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot