How to add JSON section tags to a SendGrid contact for parsing with handlebars templating language in dynamic email - handlebars.js

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!

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:
const data = {
"contacts": [
{
"email": "ryan39#lee-young.com",
"custom_fields": {
"w1": "2002-10-02T15:00:00Z",
"w33": 9.5,
"e2": "Coffee is a beverage that puts one to sleep when not drank."
}
}
]
};
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.

Related

Api Platform and Embedded Write

I have this issue with my Symfony Api Platform; I have two entities: a news and an author; every news belongs to an author.
I want to expone an API to let some external clients to add a news, using a JSON with author details; if an author already exists, the platform should be able to retrieve the author for that news, and store the news.
I embed a JSON as author, the Platform will always create a new author, also if an author with same key ( let the slug ) already exists.
Which is the best way to handle this situation? Let I have this payload:
{
"author": {
"slug": "luca"
}
"title":"news Title"
}
I expect that the API search for a user, add OR create a new one, than save the news for that author.
I add a unique constrain based the author slug, I got a database error because the platform try to store a new author every time.
But I don't want to have a public API where the client has to add an IRI , cause the client should FIRST add an author, IF NOT EXISTS on my db, THAN use the IRI ... too difficult.
Which is for you the best way to archieve this? Using some kind of event subscriber? or a DTO?
Thanks in advance

Setting up 'Trigger Email' Firebase Extension

I learned about firebase and cloud functions recently and have been able to develop simple applications with them.
I now want to expand my knowledge and really struggling with Trigger Email Extension.
On a specific event on my firebase, I want to fire an email to the user in a custom format, but I am unable to even activate the extension for now.
Can someone please explain with example please about these fields marked in the picture?
I had this question too, but got it resolved. Here's your answer:
"Email documents collection" is the collection that will be read to trigger the emails. I recommend leaving named "mail" unless you already have a collection named mail.
"Users collection (Optional)" refers to a collection (if any) that you want to use in tandem with a user auth system. I haven't had this specific use case yet, but I imagine once you understand how Trigger Email operates, it should be somewhat self-explanatory.
"Templates collection (Optional)" is helpful for templates in which you can use handlebar.js is automatically input specific information per user. (eg. <p>Hello, {{first_name}}</p> etc.) Similar to the previously mentioned collections, you can name it whatever you want.
How to create a template (I have yet to actually implement this, so take this with a grain of salt):
In your templates collection, you want to name each document with a memorable ID. Firebase gives the example:
{
subject: "#{{username}} is now following you!",
html: "Just writing to let you know that <code>#{{username}}</code> ({{name}}) is now following you.",
attachments: [
{
filename: "{{username}}.jpg",
path: "{{imagePath}}"
}
]
}
...specifying a good ID would be following. As you can see, the documents should be structured just like any other email you would send out.
Here is an example of using the above template in javascript:
firestore()
.collection("mail")
.add({
toUids: ["abc123"], // This relates to the Users Collection
template: {
name: "following", // Specify the template
// Specify the information for the Handlebars
// which can also be pulled from your users (toUids)
// if you have the data stored in a user collection.
// Of course that gets more into the world of a user auth system.
data: {
username: "ada",
name: "Ada Lovelace",
imagePath: "https://path-to-file/image-name.jpg"
},
},
})
I hope this helps. Let me know if you have an issues getting this set up.

Marketo - REST API field for Microsoft Type

In case of a sync between Marketo and Microsoft Dynamics the "Microsoft Type" field is added to leads data.
The issue is that there is no access to "Microsoft Type" field via REST API. I don't find its REST API name in the export fields document.
Any idea why it's not available or anyone knows the REST API name for Microsoft Type field?
Well, we integrated our Marketo instance with Salesforce, so I'm not 100% sure how the Type field is called in case of Microsoft Dynamics. However, based on the Salesforce integration (where the API name of the SFDC Type field is sfdcType) I would expect it to be "microsoftType".
To make sure, I would make a call to the Describe Lead API endpoint –at GET /rest/v1/leads/describe.json– to get a list of the field names available on the Lead object.
The response looks something like this:
[
{
"id":4,
"displayName":"Company Name",
"dataType":"string",
"length":255,
"rest": {
"name":"company",
"readOnly":false
},
"soap": {
"name":"Company",
"readOnly":false
}
}
// … other field descriptions
{
"id":90,
"displayName":"SFDC Type",
"dataType":"string",
"length":50,
"rest": {
"name":"sfdcType",// <- REST API name
"readOnly":true
}
}
// … other field descriptions
]
I've made a custom field(Marketo Microsoft Type) and a campaign where I assign Microsoft Type value to the new created custom field

How can I attach a custom form to a Workfront user with the API?

I have a requirement to insert new Workfront users through the API, which I am able to do. However, I need to update a Custom Form item with an employee id. With a new user, the Custom Form must be attached before the employee id can be update. I am using the following url to attach the form:
https://<url>/attask/api/user/<userguid>?sessionID=<sessionid>&updates={'objectCategories':[{'categoryID': '225845d1800010d52527455df2a27f0fe2','categoryOrder':0,'objCode':'CTGY'}]}&method=put
The result is a HTTP Error 400: Bad Request
Is it even possible to attach a Custom Form to a user? Or is there another way that it can be done through the API?
For reference, I had to work through the exact same question. You are correct in your update that you need to use the most recent version of the API (as of this post, that would be 6.0) but for others who are wondering, the syntax is as follows:
https://<url>/attask/api/v6.0/USER/<userID>?apiKey=<key>&updates={"objectCategories":[{"categoryID":"<customFormID>","categoryOrder":0,"objCode":"CTGY"}]}&method=put

Is there any way to attach the current data (as a .csv file) in PloneFormGen to a mailer?

We use PloneFormGen 1.7.12 using Plone 4.3.3. I have a request to include the current data in the email that the form is sending. We normally give editors access to the data to download, but the people he wants to send these to are not editors and I don't want to give them editor's permissions.
If it can't be added to the mailer, I guess I could create a role and give it just enough permissions for an authenticated user to download data. Would it work to copy the authenticated permissions over to a new role and add the PloneFormGen: Download Saved Input permission as well? I really don't like creating extra roles. In addition we would need to set up accounts for these people.
AFAIK not without coding :-)
Create a new DataSaveAdapter content type
Best way ist to inherit from the existing one and add a new field:
from Products.PloneFormGen.content.saveDataAdapter import FormSaveDataAdapter
SendDataAdapterSchema = FormSaveDataAdapter.schema.copy() + atapi.Schema((
atapi.StringField(
name='csv_recipients',
required=False,
widget=atapi.LinesWidget(
label=_(u'label_csv_recipients', default=u'CSV recipients'),
)
)
))
class SendDataAdapter(FormSaveDataAdapter):
implements(IPloneFormGenActionAdapter)
...
schema = SendDataAdapterSchema
...
The SaveDataAdapter provides a onSuccess method, where you can hook in and send your email
class SendDataAdapter(FormSaveDataAdapter):
...
def onSuccess(self, fields, REQUEST=None, loopstop=False):
""" saves input data and initiates mail"""
super(SendDataAdapter, self).onSuccess(fields, REQUEST, loopstop)
self.send_csv() # This is where you may implement sending the email.
Of course it needs some work to get it done (registering content type, etc.), but this should point you in the right direction.
Not really sure about your requirements, but in case you want to send the single-record in CSV-format as a mail when a form is submitted, you can customize the template of the mailer-adapter, like this:
<tal:block repeat="field options/wrappedFields | nothing">
"<span tal:replace="structure python:field.htmlValue(request)" />",
</tal:block>
Note, that this only works, if the mail's format is HTML, in plain text tal:repeat comes in the way, adding linebreaks between the values.
If you want to give a group of users permissions to view and download a save-adapter, go to PFG's controlpanel (append /prefs_pfg_permits to the site's URL), where it says "Download Saved Input" check the box for "Reader", then assign "Can edit"-permissioins via the sharing-tab of your save-adapter to the users and groups you want to be privileged.

Resources