如何将JSON部分标签添加到SendGrid联系人中,以使用动态电子邮件中的车把模板语言解析
的简要概述
我试图在SendGrid GUI中设计的动态电子邮件模板中使用SendGrid联系人的JSON数据
。 开始,在SendGrid电子邮件构建器中,我可以在CodeBlock中编写以下代码:
这是 handlebar 该代码块中的代码...
<ol>
{{#each user.accounts}}
{{#if this.isPending}}
<li>
{{this.name}} is <strong>pending activation.</strong>
</li>
{{else}}
<li>
{{this.name}} is <strong>active.</strong>
</li>
{{/if}}
{{/each}}
</ol>
我去预览该代码&amp;添加一些测试数据,我得到以下内容: 这是该代码块中格式化的JSON代码的好一点...
{
"user": {
"accounts": [
{
"name": "Checking",
"isPending": false
},
{
"name": "401k",
"isPending": true
},
{
"name": "Savings",
"isPending": true
}
]
}
}
到
目前要去。这是我撞到障碍的地方,当真实的电子邮件发送时,JSON测试数据来自联系人?以及如何使用API填充与JSON数据的联系?
据我所知,当通过API(或通过GUI)创建此访问域时,没有选择将此自定义的JSON数据添加到新的联系人中(
通过SendGrid自动化流,是否有人知道如何填充我的代码块使用的JSON,以显示已待处理/激活的帐户,并具有针对每个用户的数据?
谢谢,我非常感谢您的任何帮助!
A Brief Overview of the Problem
I am trying to store JSON data on my SendGrid contacts for usage in dynamic email templates designed in the SendGrid GUI.
To start, within the SendGrid email builder I can write the following code within a codeblock:
Here is the handlebar code in that code block...
<ol>
{{#each user.accounts}}
{{#if this.isPending}}
<li>
{{this.name}} is <strong>pending activation.</strong>
</li>
{{else}}
<li>
{{this.name}} is <strong>active.</strong>
</li>
{{/if}}
{{/each}}
</ol>
When I go to preview that code & add some test data I get the following:
Here is the JSON code in that code block formatted a bit nicer...
{
"user": {
"accounts": [
{
"name": "Checking",
"isPending": false
},
{
"name": "401k",
"isPending": true
},
{
"name": "Savings",
"isPending": true
}
]
}
}
The Question
Everything mentioned above is PERFECT so far - this is exactly what I want... To populate email data based on dynamic content present on each contact the email is going to. Here is where I hit the roadblock, where is that JSON Test Data coming from on the contact when the real email is sent out? And how do I populate a contact with JSON data using the API?
As far as I can tell, there is no option to add this custom JSON data to a new contact when creating one via the API (or via the GUI, for that matter) (see API docs here)
When I set up this email to send out to my SendGrid contacts via a SendGrid automation flow, does anyone know how to populate the JSON used by my code block for showing pending/activated accounts with data specific to each user?
Thank you, I greatly appreciate any help on this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为JSON数据实际上只有在您是时,发送带有模板的电子邮件。然后,您将JSON数据作为
dynamic_template_data
提供,并在电子邮件模板中填充。处理自动化时,您需要从联系记录本身中获取数据。您可以在模板设计师的标签部分中获取联系人的数据。
contacts上已经存在许多字段,例如
first_name
,last_name
,电子邮件
,address_line_1
等。 /管理触发/自定义场“ rel =” nofollow noreferrer“>添加自定义字段,这为您提供了可以在联系人上使用的更多字段。可以通过在您的联系人中,可以通过在CSV上载上添加新列来创建自定义字段。 sendgrid admin 或通过API创建它们。如果您使用API创建或更新联系人,则可以将
custom_fields
的对象作为API请求中的联系人记录的一部分传递。例如:请注意,当您通过API创建/更新时,要在联系人上设置自定义字段,您需要将自定义字段ID用作
custom_fields
object中的键(如上面的示例,使用IDS“ W1”,“ W33”,“ E2”)。如果您需要知道这些ID,则可以使用API获取所有字段定义。添加自定义字段后,它们也将在设计编辑器中作为标签可用,然后您可以在电子邮件设计中使用它们。
唯一的事情是,我注意到您在示例中使用了一系列帐户。如果您需要一系列任意数据,那么我不相信您可以通过联系数据和自动化来实现这一目标。您可以为一个支票帐户,401K和储蓄设置单个自定义字段。但是您不能在自定义字段中拥有任意数据。如果您确实需要数据是任意的,那么自动化可能不适合您,并且应该使用发送邮件API并提供动态模板数据发送电子邮件。
I think that JSON data is actually only useful when you are using the API to send an email with a template. You then provide the JSON data as
dynamic_template_data
and it is populated in the email template.When dealing with Automations, you need to pull the data from the contact record itself. You can get the data you have on a Contact in the Tags section of the template designer.
There are a number of fields that already exist on contacts, like
first_name
,last_name
,email
,address_line_1
, etc. You can also add Custom Fields which give you further fields you can use on your contacts. Custom Fields can be created by adding new columns on an CSV upload of your contacts, by creating them in the SendGrid admin or by creating them via API.If you are using the API to create or update your contacts, you can pass an object of
custom_fields
as part of the contact record in the API request. For example:Note that to set custom fields on a contact when you create/update by the API like this, you need to use the custom field ID as the key in the
custom_fields
object (like the example above, the IDs "w1", "w33" , "e2" were used). If you need to know those IDs, you can use the API to get all field definitions.Once you have added Custom Fields they will also be available as Tags in the design editor, then you can use them in the email design.
The only thing is, I notice you are using an array of accounts in your example. If you need an array of arbitrary data, then I don't believe you can achieve that with contact data and automations. You can set individual custom fields for, say, a checking account, 401k and savings. But you cannot have arbitrary data in a custom field. If you really need the data to be arbitrary, then Automations might not be right for you and you should send your emails out using the send mail API and providing dynamic template data.