Dynamic data in single send | Twilio SendGrid

28 views Asked by At

I am creating a monthly digest for release logs with wagtail CMS as backend, essentially whenever a new post gets created in cms, it will trigger signals.py which inturn should create a mail in single send.

Now the problem is i want to pass the data to dynamic templates. As per my knowledge marketing/single send api's doesn't support dynamic data api-docs


        dynamic_template_data = {
            "somevariable" :"John",
        }

        data = {
        "name": name,
        "send_to": {"list_ids": [list_id]},
        "email_config": {
            "suppression_group_id": unsubscribe_suppression_group,
            "sender_id": sender_id,
            # "design_id": "d-14a0041239f34f5688c5f192c869b766",
            "design_id" : "758d5b87-8b6f-49d7-ba1f-4dad111b5197",
            "dynamic_template_data": dynamic_template_data,
            "editor": "code",
        }
    }
        return self.sgClient.client.marketing.singlesends.post(request_body=data)

<!DOCTYPE html>
<html>
<head>
    <title>Your Order Details</title>
</head>
<body>
    <p>Hello {{somevariable}},</p>
</body>
</html>

This is the payload passing, initially i tried to pass the dynamic template id which isn't supported, so i passed the design id. Also i used handlebars for html template

Is there any other way to pass dynamic data for singlesend api?

[update] Response from sendgrid :

Hi there,

My name is and I am with the Twilio SendGrid senior support team. I would be happy to assist with this.

I can confirm that when sending with the Marketing features, like Single Sends, these do not support handlebars syntax in the same way that Dynamic Templates do, and you will not be able to add dynamic content using handlebars syntax and providing data in a mail send request in the way that you had outlined.

Instead Marketing Single Sends use substitution tags to add dynamic content. While the tags themselves are inserted with handlebars into the Single Send template, the full handlebars syntax is not supported. Instead of providing the data for the email in your mail send request the data that populates your Substitution Tags will come from the information you have stored about each contact in SendGrid. You can manage this information on the Marketing Campaigns Contacts page. You can find more details on how substitution tags work and how they populate here: docs [https://docs.sendgrid.com/ui/sending-email/editor#substitution-tags] and additional information on how to create custom substitution tags here: docs [https://docs.sendgrid.com/ui/managing-contacts/custom-fields]

It is important to note that even though we do offer API endpoints for sending with our Marketing features, Marketing campaigns work separately from Email API sends, and rely on contact information and data that you store within SendGrid. For working with our Single Send API, so that you can create and send Single Sends via the API, we have his resource: docs [https://docs.sendgrid.com/api-reference/single-sends/create-single-send]

I hope this helps, but please let me know if you have any additional questions or concerns.

Warm regards,

Raquel S.

Twilio Support

0

There are 0 answers