Skip to content

Transactional emails

To consider

For an email to be technically treated as transactional, it is essential that the sender is configured with the purpose "transactional emails".

For sending mail to a single contact, specific methods are provided to optimize requests and facilitate integration.

You can send an email to a single contact following the same steps as if we were using the teenvio web interface:

  • Create or update the contact
  • Create the template
  • Launch the email

But this system has the following problems:

  • Latency: 3 requests are generated for each launch
  • Accumulation of creativities: We generating a creativity template for each launch.

To solve this we have this tools:

Don't generate the template for each launch

Analyze the types of communications, For example, an e-commerce has the following types:

  • Sing up confirmation
  • password recovery
  • order confirmation
  • Shipping confirmation

Whe can build 4 teenvio templates with their respective wildcards or launch vars

Use the agrupated method

We can use the POST /bulkcampaign/ request that can unify the requests for creating a template, creating or modifying contact and launching the email, as explained in the previous point, it is highly recommended to use some templates previously created instead of generating the content of the email in each request, it will be more agile and easier to maintain.

Example

export TE_TOKEN='Your token'

curl -X POST https://app.teenvio.com/v4/public/api/rest/v3/bulkcampaign/ \
-H "X-Token: $TE_TOKEN" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '
{
    "rid" : 1,
    "name" : "transactional test from api",
    "subject" : "subject transactional email",
    "recipients" : [
        "contact1@domain.com",
        "contact2@domain.com"
    ],
    "vars" : {
        "descuento" : 20,
        "caducidad" : "noviembre"
    },
    "pid" : 26
}'
<?php

$token = 'Your token';

$url_base = 'https://app.teenvio.com/v4/public/api/rest/v3'

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_URL => $url_base.'/bulkcampaign/',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => array(
        'Accept: application/json',
        'X-Token: '.$token,
        'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => '
        {
            "rid" : 1,
            "name" : "transactional test from api",
            "subject" : "subject transactional email",
            "recipients" : [
                "contact1@domain.com",
                "contact2@domain.com"
            ],
            "vars" : {
                "descuento" : 20,
                "caducidad" : "noviembre"
            },
            "pid" : 26
        }
    '
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
import requests

token = 'Your token'

url_base = 'https://app.teenvio.com/v4/public/api/rest/v3'

my_headers = {
    'Accept' : 'application/json',
    'X-Token' : token,
    'Content-Type' : 'application/json'
}
post_request = {
    "rid" : 1,
    "name" : "transactional test from api",
    "subject" : "subject transactional email",
    "recipients" : [
        "contact1@domain.com",
        "contact2@domain.com"
    ],
    "vars" : {
        "descuento" : 20,
        "caducidad" : "noviembre"
    },
    "pid" : 26
}

response = requests.post(url_base+"/bulkcampaign/", json=post_request, headers=my_headers)

print(response.json())
const axios= require('axios');

const token = 'Your token';

const url_base = 'https://app.teenvio.com/v4/public/api/rest/v3';

const my_headers = {
    'Accept' : 'application/json',
    'X-Token' : token
};

const post_request = {
    "rid" : 1,
    "name" : "transactional test from api",
    "subject" : "subject transactional email",
    "recipients" : [
        "contact1@domain.com",
        "contact2@domain.com"
    ],
    "vars" : {
        "descuento" : 20,
        "caducidad" : "noviembre"
    },
    "pid" : 26
}

axios.post(url_base+'/bulkcampaign/', post_request, {headers:my_headers}).then(resp => {
    console.log(resp.data);
});

Response:

{
    "action": "send_bulk_campaign",
    "time": "2022-10-26 14:39:29",
    "status": "OK",
    "response": 1334,
    "code": 0
}