Prepare the request body
Learn how to structure and format the request body effectively for the Stripo API, with detailed instructions, examples, and guidelines to optimize your integration process.
In the preceding articles, we covered all the necessary preparation steps for generating email messages using the API. We also discussed the meaning of each Generate an email method parameter.
Let's closely examine the following email message we will create using the API.
Within the highlighted green rectangle, we can observe the following modules arranged from top to bottom:
- A Hero module with a banner, title, and explanation text below.
- Title module showcasing the text "Top Items" and the button on the right.
- Structure module consisting of three containers, each containing a product card.
- A structure with a "See More" button at the bottom.
Good to know
Just a friendly reminder that it is crucial to have all those modules saved in your project. Once they are saved, we extract their respective IDs.
To generate an email message like the one described, we prepare the following request based on the module type (static or dynamic).
{
"dataSources":[
{
"name":"API_canonical",
"type":"RAW",
"value":[
{
"id":"structure_with_hero_section"
},
{
"id":"structure_with_title_and_cta"
},
{
"id":"structure_empty_3_containers",
"content":[
{
"id":"product_card",
"values":{
"url":"https://my.store.com/1",
"p_name":"Burger Deluxe",
"p_image":"https://stripocdn.email/content/guids/CABINET_bb3fcdd24c9db8847ad38a4aed1beecdc1b0954412c0bce53f279d420cef8bac/images/g508c2454742bc875d5b894928707586f6f84c72f9394d53dc84ae96c3dc17c0ca6602b92d982eb976a550bd2560065.jpeg",
"p_price":"$9.99",
"p_description":"Classic beef burger with special sauce."
}
},
{
"id":"product_card",
"values":{
"url":"https://my.store.com/2",
"p_name":"Crispy Chicken",
"p_image":"https://stripocdn.email/content/guids/CABINET_bb3fcdd24c9db8847ad38a4aed1beecdc1b0954412c0bce53f279d420cef8bac/images/g6b5990d1f0152cc8abf1a15e3e67eee115aedce8899879a8d0921fa07ef458605bcca5441bffb2a1fb085b3b17895c.jpeg",
"p_price":"$8.99",
"p_description":"Tender fried chicken with a crispy coating."
}
},
{
"id":"product_card",
"values":{
"url":"https://my.store.com/3",
"p_name":"Cheese Pizza",
"p_image":"https://stripocdn.email/content/guids/CABINET_bb3fcdd24c9db8847ad38a4aed1beecdc1b0954412c0bce53f279d420cef8bac/images/g62bebef9194ff3ce2b3dc3c486eadf1dc13daf2866ff31ac97f50ecc38f280d8e6ad47e7a95bd32b71ff4152d740f8.jpeg",
"p_price":"$10.99",
"p_description":"Traditional cheese pizza with a thin crust."
}
}
]
},
{
"id":"structure_empty_3_containers",
"content":[
{
"id":"product_card",
"values":{
"url":"https://my.store.com/4",
"p_name":"Spicy Wings",
"p_image":"https://stripocdn.email/content/guids/CABINET_bb3fcdd24c9db8847ad38a4aed1beecdc1b0954412c0bce53f279d420cef8bac/images/g73c4730dff9673ada7830cd31ec8383e917145e313fade955f2eb4fb97811ab713a7f30a900ad2ace427938bf36279.jpeg",
"p_price":"$7.99",
"p_description":"Hot chicken wings with a tangy sauce."
}
},
{
"id":"product_card",
"values":{
"url":"https://my.store.com/5",
"p_name":"Veggie Wrap",
"p_image":"https://stripocdn.email/content/guids/CABINET_bb3fcdd24c9db8847ad38a4aed1beecdc1b0954412c0bce53f279d420cef8bac/images/g6f1f0b6392ed7d69c9963709df64027471ad48b367300e06619b9e308365a6e9a44f918c31c8e77ad259ff7285a74e.jpeg",
"p_price":"$6.99",
"p_description":"Fresh vegetable medley wrapped in a tortilla."
}
},
{
"id":"product_card",
"values":{
"url":"https://my.store.com/6",
"p_name":"Loaded Fries",
"p_image":"https://stripocdn.email/content/guids/CABINET_bb3fcdd24c9db8847ad38a4aed1beecdc1b0954412c0bce53f279d420cef8bac/images/ge5457c2f851237616836280c07f5bc4091bb21d00fc4b560749d34692c35b7260e521ea1ba89fdc47ce4cc4c82f74b.jpeg",
"p_price":"$5.99",
"p_description":"Crispy fries topped with melted cheese."
}
}
]
},
{
"id":"structure_with_cta"
}
]
}
],
"transformers":[
],
"composers":[
],
"templateId":12345678,
"emailName":"API_doc_canonical"
}
In the provided example, you may observe that we have included information about the data and modules within the dataSources
parameter using the RAW
type. This is because the data is directly present in the request itself and not sourced from elsewhere (e.g., LINK
). Within this parameter, we define an array of modules in the order they should appear from top to bottom in the final email message.
The first module in the request is a static Banner with the ID "structure_with_hero_section"
.
Following that is a static module with the Title, identified by the ID "structure_with_title_and_cta"
.
Afterward, we include the ID of an empty structure with two containers specified as "id":"structure_empty_3_containers"
. Inside this structure, we define the module's ID representing each container, denoted as "id":"product_card"
. For each container, we provide values for the respective variables within the saved module.
Subsequently, a static module is placed with the ID "structure_with_cta"
. As it is a static module, there is no need to specify its values, and it will be inserted as it was initially saved without any changes.
Since there are no data transformations required, the transformers
parameter is left empty.
Similarly, the composers
parameter is also left empty as only one generation area is in the template used to generate the email message.
Please be advised
In the
composers
parameter, you can specify the name of the generation area where you want to insert the data. We previously discussed this in the "Preparing to create emails" section.If the
composers
parameter is empty in your request, the API will search for the first available generation area and insert the data there.However, if your prepared template contains multiple generation areas, it is recommended to specify the desired area in your request to ensure that the data is inserted into the correct one using the API.
The templateId
is specified after the composers
parameter and it represents the ID of our prepared template. This template will serve as the foundation for creating a new email message. Stripo will utilize the HTML and CSS from that template, keeping the content unchanged. However, it will identify the generation area and insert the content from your request into that area.
Now, creating your inaugural email message using the API is your turn.
We're here to help!
If you have any questions or encounter any difficulties, please don't hesitate to contact our team at [email protected]. We will be more than happy to assist you!
Updated over 1 year ago