All Collections
Editor Questions
Additional Features
How simply create emails with Stripo API using the SRT transformer
How simply create emails with Stripo API using the SRT transformer

This article will explore the same API method for generating email messages but with a slight modification using SRT method.

Oleh Tokariev avatar
Written by Oleh Tokariev
Updated over a week ago

What are the SRT Transformers?

This is one of the most important transformers, which defines the rules for placing modules in your email.

The great thing is that you can vary the set of modules depending on any of the parameters you received from the data source. This helps to create complicated rules.

The transformer we're discussing here plays a crucial role since it controls where modules are placed within your email message. What's even more impressive is that you can modify the collection of modules based on any data source criteria. You can create complicated email layouts and set up complex rules according to this level of adaptability.

SRT

It is divided into 3 sections:

  • Start section — here, you can define which modules should be placed at the very beginning of the auto-generated area;

  • Repeatable section — here, you can set a rule of what modules should be used for each loop (circle). This is very helpful in case you want to alternate different modules or use some specific modules on every X circle;

  • Tail section — this is the place where you can set a rule for displaying a particular module in case there are no enough items (products) in your data source to complete the whole circle from a repeatable area.

As in practice, the chosen order of modules probably will be the same for some of your other emails; we have an option to operate with the SRT rules via REST methods (like save/reuse and delete them). So, after you configured and saved your SRT rules, it is possible to reuse them again — call them by name and set a few config parameters needed for applying in your particular email template.

More info about how to operate the SRT rules and supported rules can be found in the REST API Methods description.

However, let's go in order of creation.

At first, in order to start generating an email using the Stripo API, we will distribute the template and modules preparation using 1st and 2nd stages described in this article on how to prepare modules and a dynamic area.

SRT configuration:

Within the API Reference page, several methods are dedicated to managing SRT transformers.

Let's briefly go over the necessary elements and how to make them. In the following sections, we'll go through specific examples of creating SRT transformers as well as sample body requests to generate emails using created SRT transformers. To create an SRT transformer, you need to specify the name and designate the config type. These two parameters are essential in defining the transformer and its configuration.

JSON

{
name: String,
config: JSON
}

Four methods for the SRT transformer:

This method allows saving a new SRT rule with a given name for further reuse in the email generation method.

SrtConfigDto entity

{ name: String, config: JSON }

This method allows getting the list of all saved SRT rules for the project. In response, the array with all SRT rules’ names will be returned.

GetSrtConfigNamesDto entity

[ { name: String } ]

This method allows receiving the configuration for already saved SRT rule. In the GET parameter, it is required to specify the name of a needed one.

As a result, you will see the SrtConfigDto entity described in the Save new SRT rule method.

4. Delete particular SRT rule /srt?name={name}

This method allows deleting the already saved SRT rule. In the DELETE parameter, it is required to specify the name of a needed one.

If the request has been processed successfully, you will get the 200-OK response code with an empty body.

There are other different methods you can use to call different actions. For more methods, please click here.


Description of the structure of needed parameters for the JSON:

Scroll down for a description of each of the following fields.

{
start: [
{
id: String
}
],
repeatable: [
{
id: String,
rules: {
enum
}
}
],
tail: [
{
id: String
}
]
}

Where:

  • start, repeatable, tail — These are the section names where you define the rules for the layout of modules in your email;

  • id — This refers to the Unique Identifier (UID) of the module that has been saved to the Library. It helps identify and reference the specific module you want to use;

  • rules — This parameter denotes the name of the conditional rule applied to a particular module. You can apply different conditional rules to modules based on your requirements. Please refer to the Resources documentation to access the detailed list of conditional rules that can be applied to modules in your email template.

It is possible to set skipValue:true parameter for any module in case you don’t need to apply content to it.

For more about possible fields and their description, please follow here.

There are 2 Samples of requests described in the documentation, please click here for more details.

In our case, we will consider the Sample A.


Assumptions Made for Design Requirements

The generating section needs to have a static banner and a catchy title in addition to the template's static header and footer. Each row should have two product cards displayed after the title, repeating as long as data values are in the data source query. However, there will be a change in the repetitive section on the second cycle, including three product cards in a row. A single card will be centered in each row if there isn't enough information to fill two cards in a row.

The elements that follow must be the final message design:

Creation of SRT transformer:

The actions listed below must be completed in order to create an email message utilizing an SRT transformer and achieve the necessary design:

  • Start section: The banner and title modules in this area are static. We can use the skipValue:true parameter since these modules are kept unchanged and don't need data injection from the dataSources.

  • Repeatable section: This section should contain modules of an empty structure with three containers and defined modules for each container. However, we must use a structure with a button at the very bottom in case there are no more items in the data source.

  • Tail section: We will only enter this section if there are not enough elements (products) in our data source to fill one row with three containers completely. This ensures that any remaining cards from the repeatable section are placed appropriately. We will have only two rules in the tail section. The first rule includes a module with a structure and a single container where we will place the same module with one product. And the second rule includes a structure with two containers where we will place the same module with two products.


Below is the code for the configuration as requested:

The query structure:

// QUERY STRUCTURE
{
dataSources: DataSourceDto[],
transformers: TransformerDto[],
composers: ComposerDto[],
templateId: Long,
emailId: Long,
emailName: String,
title: String,
preheader: String
}

JSON

{
"name":"SRT_example_A",
"config":{
"start":[
{
"id":"structure_with_hero_section",
"skipValue":"true // States data inapplicable to current module."
},
{
"id":"structure_with_title_and_cta",
"skipValue":true
}
],
"repeatable":[
{
"id":"structure_empty_3_containers",
// UID of the empty structure with 3 containers saved to the Modules."content":[
{
"id":"product_card"
},
{
"id":"product_card"
},
{
"id":"product_card"
}
]
},
{
"id":"structure_with_cta",
"See More""button saved to the Modules.""rules":{
"records":0 // The rule states that the object can be used only when there are no more items left in the data source after the cycle is completed.
}
}
],
"tail":[
{
"id":"structure_empty_1_container",
"content":[
{
"id":"product_card"
}
],
"rules":{
"records":1 // The rule states that the object can be used only when there is one item left in the data source after all the cycles are completed.
}
},
{
"id":"structure_empty_2_containes2",
"content":[
{
"id":"product_card"
},
{
"id":"product_card"
}
],
"rules":{
"records":2 // The rule states that the object can be used only when there are two items left in the data source after all the cycles are completed.
}
}
]
}
}

Preparing the request body to create an email message:

After generating the SRT rule, we can apply it by making a POST request to generate the email message. Below is a sample body request with row data:

JSON

{
"dataSources":[
{
"name":"Source for SRT",
"type":"RAW",
"value":[
{
"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."
},
{
"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."
},
"... // Add as many data objects as necessary in this location."{
"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."
},
{
"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."
},
{
"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."
},
{
"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."
}
]
}
],
"transformers":[
{
"type":"srt",
"config":{
"name":"SRT_example_A"
}
}
],
"composers":[

],
"templateId":"123456789",
"emailName":"SRT_example_A"
}

Some other parameters for email generation

  • emailId int64 - In case you want to override an already existing email template, please specify its ID here. If this field is empty than a new email will be created;

  • emailName string - This is the name that will be given to a generated email. If the field is empty then the name of a template will be used as a name of the generated email;

  • title string - An email title;

  • preheader string - The email preheader;

Done! We will receive the email message created in accordance with the given requirements by submitting the request. The dataSources section in the request should be changed in order to create a new email message with the same design but different data. Since they have already been saved and may be referred to simply specifying the appropriate name in the request, there is no need to update the SRT transformer itself or the module location. When creating email messages with the same design but different data, this method saves us time and is convenient, effective.

*Your email should be generated in "Email Messages" tab.


Thank you for taking the time to read our articles. We hope you will find this information helpful.


If you have any additional questions, please email us at support@stripo.email.

We would be glad to talk with you.


Did this answer your question?