Sendgrid-nodejs: Are sections working correctly with v3 API ?

Created on 22 Sep 2016  路  2Comments  路  Source: sendgrid/sendgrid-nodejs

Issue Summary

I am using templates with section and substitutions tags, the problem is that the defined section tags won't get filled at all. All the defined substitutions tags get's filled correctly, e-mail gets no validation errors and is sent out correctly.

In Sendgrid module repo the example is using the old v2 format? https://github.com/sendgrid/sendgrid-nodejs/blob/master/examples/mail/mail.js#L142

The API request body looks like this:

const body = {
    "from": {
        "email": "noreply@...",
        "name": "...",
    },
    "personalizations": [{
        "to": [
            {
                "email": "risto@...",
            },
            {
                "email": "est@...",
            }
        ],
        "substitutions": {
            "[%person_avatar%]": "https://...",
        },
    }],
    "sections": {
        "[%name%]": "John Manni",
        "[%team_avatar%]": "https://...",
        "[%team_name%]": "Dev & Ops",
        "[%custom_message_headline%]": "Come quick",
        "[%custom_message%]": "Help",
    },
    "template_id": "...-8325-6a875b6abe57",
};

Technical details:

  • sendgrid-nodejs Version: 4.3.0
  • Node.js Version: 6.6.x
help wanted bug

Most helpful comment

Just to check - the sections should be added via a substitution tag. This is a legacy "feature" that we have, but is definitely the case.

Can you please double check that you have a sub that gets replaced with the section tag? It should be like this:

const body = {
    "from": {
        "email": "noreply@...",
        "name": "...",
    },
    "personalizations": [{
        "to": [
            {
                "email": "risto@...",
            },
            {
                "email": "est@...",
            }
        ],
        "substitutions": {
            "[%section_1%]": "[%the_section_tag%]",
        },
    }],
    "sections": {
        "[%the_section_tag%]": "a block of html or text that will be included when this tag is replaced"
    },
};

... just make sure your content includes the tag [%section_1%] for the replacements.

Sections are really good for bigger blocks of text that will be used across multiple personalizations (individual emails that are sent) and can contain substitution tags as well.

For example, if you wanted to send the same block of text but replace the product information for customers who ordered recently, but not for customers who need to come back to your store, you could do it this way: _(note: Customer who ordered gets one section, customer who hasn't gets the other. You could get much further into this with substitutions as well)_

    "personalizations" : [
        {
        "to":[{"email":"[email protected]"}],
        "substitutions": {
            "[%product_info%]": "[%has_product%]",
        },
    },        {
        "to":[{"email":"[email protected]"}],
        "substitutions": {
            "[%product_info%]": "[%no_product%]",
        },
    }],
     "content": [
    {
      "type": "text/plain",
      "value": "We just wanted to tell you that we appreciate you being a long time customer! [%product info%]"
    }
  ],
    "sections": {
        "[%has_product%]": "Also, thanks for ordering:<br />[%product_section%].<br /> Are you ready to order again!?",
        "[%no_product%]": "You haven't ordered in a while, but we'd love it if you came back and saw our new products!"
    }

All 2 comments

Hello @riston,

I'll have to dig deeper on this one. To help me duplicate the issue, can you share the template with me? If you prefer, please email it to us at [email protected].

Thanks!

Just to check - the sections should be added via a substitution tag. This is a legacy "feature" that we have, but is definitely the case.

Can you please double check that you have a sub that gets replaced with the section tag? It should be like this:

const body = {
    "from": {
        "email": "noreply@...",
        "name": "...",
    },
    "personalizations": [{
        "to": [
            {
                "email": "risto@...",
            },
            {
                "email": "est@...",
            }
        ],
        "substitutions": {
            "[%section_1%]": "[%the_section_tag%]",
        },
    }],
    "sections": {
        "[%the_section_tag%]": "a block of html or text that will be included when this tag is replaced"
    },
};

... just make sure your content includes the tag [%section_1%] for the replacements.

Sections are really good for bigger blocks of text that will be used across multiple personalizations (individual emails that are sent) and can contain substitution tags as well.

For example, if you wanted to send the same block of text but replace the product information for customers who ordered recently, but not for customers who need to come back to your store, you could do it this way: _(note: Customer who ordered gets one section, customer who hasn't gets the other. You could get much further into this with substitutions as well)_

    "personalizations" : [
        {
        "to":[{"email":"[email protected]"}],
        "substitutions": {
            "[%product_info%]": "[%has_product%]",
        },
    },        {
        "to":[{"email":"[email protected]"}],
        "substitutions": {
            "[%product_info%]": "[%no_product%]",
        },
    }],
     "content": [
    {
      "type": "text/plain",
      "value": "We just wanted to tell you that we appreciate you being a long time customer! [%product info%]"
    }
  ],
    "sections": {
        "[%has_product%]": "Also, thanks for ordering:<br />[%product_section%].<br /> Are you ready to order again!?",
        "[%no_product%]": "You haven't ordered in a while, but we'd love it if you came back and saw our new products!"
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kiranshashiny picture kiranshashiny  路  4Comments

amlcodes picture amlcodes  路  4Comments

murphman300 picture murphman300  路  4Comments

thinkingserious picture thinkingserious  路  4Comments

metalshan picture metalshan  路  3Comments