Mandrill API with Handlebars "each-loop" not working - go

Met problem when using Mandrill API to send transactional newsletters. I chose Handlebars for the template parameters. The user name was shown correctly, but data in the list (post titles) were empty. Please help indicate if anything I did wrong. Thank you!
The template is as below, sent to the endpoint /messages/send.json :
func genHTMLTemplate() string {
return "code generated template<br>" +
"Hi {{name}}, <br>" +
"{{#each posts}}<div>" +
"TITLE {{title}}, THIS {{this}}<br>" +
"</div>{{/each}}"
}
The API log in my Settings panel in mandrillapp.com shows the parameters:
{
"key": "xxxxxxxxxx",
"message": {
:
"merge_language": "handlebars",
"global_merge_vars": null,
"merge_vars": [
{
"rcpt": "xxxxxx#gmail.com",
"vars": [
{
"name": "posts",
"content": [
{
"title": "title A"
},
{
"title": "title B"
},
]
},
{
"name": "name",
"content": "John Doe"
}
]
}
],
:
},
:
}
And below is the email received. "title A" and "title B" are expected after "TITLE".
code generated template
Hi John Doe,
TITLE, THIS Array
TITLE, THIS Array

Mandrill decided to create custom handlebars helpers with some horrible, HORRIBLE names:
https://mandrill.zendesk.com/hc/en-us/articles/205582537-Using-Handlebars-for-Dynamic-Content#inline-helpers-available-in-mandrill
title and url will definitely give you grief if your objects happen to have keys named title and urlas well. Why they didn't name their helpers something like toTitleCase and encodeUrl is beyond me.
As far as arrays and #each is concerned, you can work around it by using {{this.title}} instead of {{title}}.

After testing with Mandrill's sample code here I found the key "title" just doesn't work. Dunno the reason (a reserved keyword of Mandrill?) but replace it with "title1", "titleX" or something else it can be rendered correctly.
{
"name": "posts",
"content": [
{
"title": "blah blah" // "title1" or something else works
},
}

while using handlebars as the merge language 'title' is the reserved helpername which is used in handlebars which makes your text in title case. If you do only {{title}} by default it considers as title the empty text. try giving it {{title title}} which should work or changing the key name to something else ( if you dont want your title in title case )

I know this is late but it could be of use to someone trying to debug this issue currently. Take note of this point in the Mandrill documentation
There are two main ways to add dynamic content via merge tags: Handlebars or the Mailchimp merge language. You may already be familiar with the Mailchimp merge language from creating and editing Mailchimp templates. We also offer a custom implementation of Handlebars, which is open source and offers greater flexibility.
To set your merge language, navigate to Sending Defaults and select Mailchimp or Handlebars from the Merge Language drop-down menu.
I've run into a similar issue on Sending Blue, where their default configuration does not enable handle bars so it won't evaluate them.

Related

Is there a way to write an Expression in Power Automate to retrieve item from SurveyMonkey?

There is no dynamic content you can get from the SurveyMonkey trigger in Power Automate except for the Analyze URL, Created Date, and Link. Is it possible I could retrieve the data with an expression so I could add fields to SharePoint or send emails based on answers to questions?
For instance, here is some JSON data for a county multiple choice field, that I would like to know the county so I can have the email sent to the correct person:
{
"id": "753498214",
"answers": [
{
"choice_id": "4963767255",
"simple_text": "Williamson"
}
],
"family": "single_choice",
"subtype": "menu",
"heading": "County where the problem is occurring:"
}
And basically, a way to create dynamic fields from the content so it would be more usable?
I am a novice so your answer will have to assume I know nothing!
Thanks for considering the question.
Overall, anything I have tried is unsuccessful!
I was able to get an answer on Microsoft Power Users support.
Put this data in compose action:
{
"id": "753498214",
"answers": [
{
"choice_id": "4963767255",
"simple_text": "Williamson"
}
],
"family": "single_choice",
"subtype": "menu",
"heading": "County where the problem is occurring:"
}
Then these expressions in additional compose actions:
To get choice_id:
outputs('Compose')?['answers']?[0]?['choice_id']
To get simple_text:
outputs('Compose')?['answers']?[0]?['simple_text']
Reference link here where I retrieved the answer is here.
https://powerusers.microsoft.com/t5/General-Power-Automate/How-to-write-an-expression-to-retrieve-answer/m-p/1960784#M114215

Elastic/Opensearch: HowTo create a new document from an _ingest/pipeline

I am working with Elastic/Opensearch and want to create a new document in a different index out of an _ingest/pipeline
I found no help in the www...
All my documents (filebeat) get parsed and modified in the beginning by a pipline, lets say "StartPipeline".
Triggered by an information in a field of the incoming document, lets say "Start", I want to store that value in a special way by creating a new document in a different long-termindex - with some more information from the triggering document.
If found possibilities, how to do this manually from the console (update_by_query / reindex / painlesscripts) but it has to be triggered by an incoming document...
Perhaps this is easier to understand - in my head it looks like something like that.
PUT _ingest/pipeline/StartPipeline
{
"description" : "create a document in/to a different index",
"processors" : [ {
"PutNewDoc" : {
"if": "ctx.FieldThatTriggers== 'start'",
"index": "DestinationIndex",
"_id": "123",
"document": { "message":"",
"script":"start",
"server":"alpha
...}
}
} ]
}
Does anyone has an idea?
And sorry, I am no native speaker, I am from Germany

How to get name/confidence individually from classify_text?

Most of the other methods in the language api, such as analyze_syntax, analyze_sentiment etc, have the ability to return the constituent elements like
sentiment.score
sentiment.magnitude
token.part_of_speech.tag
etc etc etc....
but I have not found a way to return name and confidence in isolation from classify_text. It doesn't look like it's possible but that seems weird. Am missing something? Thanks
The language.documents.classifyText method returns a ClassificationCategory object which contains name and confidence. If you only want one of the fields you can filter by categories/name or categories/confidence. As an example I executed:
POST https://language.googleapis.com/v1/documents:classifyText?fields=categories%2Fname&key={YOUR_API_KEY}
{
"document": {
"content": "this is a test for a StackOverflow question. I get an error because I need more words in the document and I don't know what else to say",
"type": "PLAIN_TEXT"
}
}
Which returns:
{
"categories": [
{
"name": "/Science/Computer Science"
},
{
"name": "/Computers & Electronics/Programming"
},
{
"name": "/Jobs & Education"
}
]
}
Direct link to API explorer for interactive testing of my example (change content, filters, etc.)

Structuring data in Firebase for multiple hashtags during parse to Firebase migration

Firebase Data is structured as JSON. As per the best practice we should create denormalised form of Data. We should push same data in different nodes. As per their documentation it is okay to duplicate data in different branch.
How should I structure this data in Firebase?
I am writing a blogging application that was there in PARSE and wants to migrate to Firebase .
Each of my Blog is having different hashTags. These HashTags are clickable. So when we click a particular hashTag it will redirect to a page with common blogs having same hashTags .
How do we conceptualize above hash tag behaviour in Firebase.
How to structure the data so that i can query all blogs for a particular hashtag ?
like select * from [blogs] where tag = '#hashtag'
Try this
blogs
blog_01
hashtag:"#hashtag"
data: "some data"
blog_02
hashtag: "#anotherHashtag"
data: "more data"
blog_03
hashtag: "#superHashtag"
data: "another data"
and the code
ref = rootRef.childByAppendingPath("blogs")
ref.queryOrderedByChild("hashtag").queryEqualToValue("#anotherHashtag")
.observeEventType(.Value, withBlock: { snapshot in
//.Value can return multiple nodes within the snapshot so iterate over them
for child in snapshot.children {
let hash = child.value.objectForKey("data") as! String
print(hash) //prints 'more data'
}
})
Edit: This is OS X Swift code but you can get the general idea as it applies across platforms.
I think Firebase wants you to do something similar to this:
{
"blogs": {
"blog1": {
"name": "blogpost1",
"text": "blogpost1 text"
"tags": {
"tag1": true,
"tag2": true,
"tag3": true
}
},
"blog2": {
"name": "blogpost2",
"text": "blogpost2 text"
"tags": {
"tag1": true
}
},
"blog3": {
"name": "blogpost3",
"text": "blogpost3 text"
"tags": {
"tag1": true
}
}
}
{
"tags": {
"tag1": {
"blog1": true,
"blog2":true,
"blog3":true,
},
"tag2": {
"blog1":true
},
"tag3": {
"blog1":true
}
}
}
I hope this helps. Essentially you would query your tags json with the each tag containing the key for a respective blog post. A good next step would be to probably, as opposed to putting true as a value in the tags, put a date so that you can order the post in your search results sequentially.
Post what you came up with as a solution please.

MailChimp Campaign Update

i am trying to use campaigns/update in MailChimp.
However i still cannot understand how can i use it.
Can anyone please explain to me, for example how can i change the "from_email" parameter?
my current json for that purpose looks like this:
{
"apikey": "my_api_key",
"cid": "my_campaign_id",
"name": "options",
"value": ["list_id_value","subject_value","from_email_value"]
}
However when i send this json to campaigns/update, it returns error saying that "Can not update unknown option "2"".
How can i change the json so that i can update the "from_email"?
The API docs seem to be wrong. Try replacing [ ] with { } and giving field:pair values inside it. So, example to change the subject:
{
"apikey": "my_api_key",
"cid": "my_campaign_id",
"name": "options",
"value": {"subject": "My new subject"}
}

Resources