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 parameters you received from the data source. This helps to create complicated rules.

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 particular module in case if there is no enough items (products) in your data source to complete the whole circle from a repeatable area.

Here is a short example of using SRT transformer. Let's say you would like to place at the very beginning of auto-generated area of email the modules as follows:

  • the module with big banner depending on user’s preferences, then

  • the module with big static banner (regardless user’s preferences), then

  • the module with two containers underneath for all rest items (products), then

  • the module with three containers in 1 line on the 3rd circle of the repeatable section with products for children in case if there is “kids” category in the data source, after that

  • the last module should be also a big banner in case there is an odd number of products remained.

The general view of modules layout will be like in the image below.

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 — simply call them by name and set a few config params needed for applying in your particular email template.

More info about how to operate the SRT rules and supported rules you can find 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 preparation by stages.


Stage 1: We save our elements: banners and product cards into modules.

I saved this simple banner as a module:

And set it's unique ID: structure_banner_top

I have got a structure with 3 containers with product cards and first of all I need to create and save as a module the empty structure with 3 containers as well. The product cards will be defined and filled into these containers.

And set it's unique ID: empty_structure_3_containers

Let's prepare product card as well.

The product cards need to have Smart properties to be able to automatically replace data in it.


How to set smart properties?

The article https://support.stripo.email/en/articles/5462454-what-are-the-smart-element-and-how-to-use-them will help you to do it.

Basically we need to set unique variables for product card's elements:

Then set relevant unique classes to these elements in code:


Save only one smart container as a module and set it's ID: product_card

Save other need structures and modules and set their ID.

First Stage has DONE!


Stage 2: Create an auto-generation area within the desired template for the email generation.

Let's copy your template. Please kindly leave your need header and footer in it since they will be static. And then please remove all content area. The result should look like here:

The easiest item is the last one. Please, choose the template for your auto-generation emails. This template should be yours (saved in the project you have access to), not the basic or public. Basically, it may have some static elements like Header and Footer, etc. AND it should have at least one stripe with a special class, needed to determine the place where exactly the content should be inserted in when the Generate Email method is called.

For this purpose, please add an empty stripe with one column and add the esd-email-gen-area="name_of_area" class to the td tag of the stripe in the code editor where the name_of_area is the given name.

Example of the stripe with area for email auto-generation, called products-area.

<td class="esd-stripe" align="center" esd-email-gen-area="products-area">

Done!


Stage 3: JWT token for authentication of all REST API calls

  • Get a JWT token for authentication of all REST API calls.

To generate a JWT token please move to your Project settings > scroll down to Access to the REST API and copy it.

  • REST API Info

The Stripo API is a standard REST API that supports basic CRUD operations and may be used by the 3rd party applications to automate the email templates creation and planning their further exports and mailings.

Every POST request MUST HAVE Content-Type header. Currently, we accept only 'application/json' content-type.

The data request is passed to the API by POSTing JSON objects to the API endpoints with the appropriate parameters. The documentation for each API call will contain more details on the parameters accepted by the call.

  • API Endpoint

All API URLs listed in this documentation are relative to https://stripo.email/emailgeneration/v1/.

For example, the /email call is reachable at https://stripo.email/emailgeneration/v1/email.

  • Download Postman

  • Authentication

Once you obtain your JWT token, you will have to use it in every API call you make. The token value must always be specified in a header in every query as shown in the example below:

Stripo-Api-Auth: YOUR_JWT_TOKEN

Let's check that the token is valid:

To do so please click on a "+" on the left-top corner of a screenshot and create a New collection.

Then set GET method and add /validate to the API URL

( https://stripo.email/emailgeneration/v1/validate )

Please set two keys and their value:

Key

Value

Stripo-Api-Auth:
YOUR_JWT_TOKEN
Content-Type
application/json

Now you can send a GET call by clicking on the blue button "SEND" and if you have the answer "valid": true in the Body your token is valid. Status 200 ok.

For more info about status codes please follow here.

We can use four methods for SRT transformer:

1. Save new SRT rule /srt

This method allows saving new SRT rule with a given name for further re-use in email generation method.

SrtConfigDto entity

{ name: String, config: JSON }

2. Get list of all SRT rules /srtnames

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 } ]

3. Get configuration for particular SRT rule /srt?name={name}

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 GET parameter, it is required to specify the name of a needed one.

In case 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.

Stage 4: Using the 1-st method /srt create and save SRT rule in Postman

Download the Postman.

At first we need to create SRT rule where the order of elements will be defined.

It's more flexibly to canonical json as you pass ID's of your saved modules only.

According to the Stage 3 please create another New Collection by clicking on "+" icon

Then set POST method and add /srt to the API URL

( https://stripo.email/emailgeneration/v1/srt )

Please set same two keys in the Headers tab:

Key

Value

Stripo-Api-Auth:
YOUR_JWT_TOKEN
Content-Type
application/json

Then please switch with the tab Body, choose raw type and you are ready to create your SRT rule.

Description of structure of needed parameters for the JSON:

Scroll down for a description of each following fields.

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

where:

start, repeatable, tail — these are the names of the sections where the rules for a module layout should be set;

id — the UID of the module saved to the Library;

rules — the name of the conditional rule applied to the particular module. The list of supported conditional rules may be found in Appendix.

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

For more details please follow here.

See our sample of a JSON:

// INSERTED DATA
{
"name": "Name of your SRT",
"config": {
"start": [
{
"id": "structure-smart-100"
},
{
"id": "structure-simple-30-30-30",
"content": [
{
"id": "product-card"
},
{
"id": "banner-block",
"skipValue": true
},
{
"id": "product-card"
}
]
}
],
"repeatable": [
{
"id": "structure-smart-100",
"rules": {
"every": 2
}
},
{
"id": "banner2-100",
"skipValue": true,
"rules": {
"only": 4
}
},
{
"id": "structure-simple-50-50",
"content": [
{
"id": "product-card"
},
{
"id": "product-card"
}
],
"rules": {
"start": 2
}
}
],
"tail": [
{
"id": "tail-banner-100",
"skipValue": true
},
{
"choice": [
{
"id": "structure-simple-50-tail",
"content": [
{
"id": "product-card"
},
{
"id": "product-card"
}
],
"rules": {
"records": 2
}
},
{
"id": "structure-smart-100-tail",
"mapping": {
"p_big_image": "p_image"
},
"rules": {
"records": 1
}
}
]
}
]
}
}

As you could see from our sample of a JSON I used rules.

Rules are conditions for your elements and respond for the action that will be applied to the certain element where this rule will be added.

For instance:

The rule "every": 2 means the element will be showed every second circle in repeatable section.

Number "2" is a loop number as well.

For more info about supported conditional rules please follow here.

Stage 5: Generate email on a base of saved SRT rule

The query structure:

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

You pass necessary only the data of your smart modules to the dataSource and set the type of transformer - srt.

Config - your saved srt rule

{
"dataSources":[
{
"name":"Dnepr",
"type":"RAW",
"value":[
{
"p_name":"Smart watch Amazfit GTS 2 mini (Black) Dnepr", "p_image":"https://lgjfwj.stripocdn.email/content/guids/CABINET_68e73c39d0a290d4ae9b44abaab36c1e/images/70911617265374547.png",
"p_price":"$70"
},
{
"p_name":"Apple iPhone 12 Pro Max 128GB Graphite", "p_image":"https://lgjfwj.stripocdn.email/content/guids/CABINET_68e73c39d0a290d4ae9b44abaab36c1e/images/90671617265373265.png",
"p_price":"$1410"
},

{
CONTINUE PASSING ALL YOUR NECESSARY DATA FOR SMART MODULES
}

]
}
],
"transformers":[
{
"type":"srt",
"config":{
"name":"Your_saved_SRT_rule"
}
}
],
"composers":[

],
"templateId":"1234567",
"emailName":"Name_for_your_email",
"title": "Your title",
"preheader": "Your preheader"
}

Done. Your email should me generated in Emails tab

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

Did this answer your question?