Question

I'm sending a template email from Mandrill API like this:

{
   "key":"xxxyyyzzz",
   "template_name":"coupon-purchased",
   "template_content":[
   ],
   "message":{
      "to":[{"email":"xxx@yyy.com"}]
   },
   "merge":true,
   "global_merge_vars":[
      {
         "name":"FNAME",
         "content":"Your name"
      },
      {
         "name":"FGYMNAME",
         "content":"Your gym"
      }
   ],
   "merge_vars":[
   {
      "rcpt": "xxx@yyy.com",
      "vars":[
         {
            "name":"FNAME",
            "content":"Your name"
         },
         {
            "name":"FGYMNAME",
            "content":"Your gym"
         }
      ]
   }]
}

As a POST message to this URL: https://mandrillapp.com/api/1.0/messages/send-template.json

I've tried with some HTML document, but finally I'm just using the following as template:

*|FNAME|* and *|FGYMNAME|*

But still not working. Those variables are not exchanged with the values sent in global_merge_vars.

Also, I've tried to remove merge_vars and merge properties from JSON, not working neither.

Any clues about it?

Thanks!

Was it helpful?

Solution

It looks like you don't have the merge_vars, merge, and global_merge_vars parameters within the message. They should be nested in the message to take effect. So it would look something like this:

{
    "key": "xxxyyyzzz",
    "template_name": "coupon-purchased",
    "template_content": [],
    "message": {
        "to": [
            {
                "email": "xxx@yyy.com"
            }
        ],
        "merge": true,
        "global_merge_vars": [
            {
                "name": "FNAME",
                "content": "Your name"
            },
            {
                "name": "FGYMNAME",
                "content": "Your gym"
            }
        ],
        "merge_vars": [
            {
                "rcpt": "xxx@yyy.com",
                "vars": [
                    {
                        "name": "FNAME",
                        "content": "Your name"
                    },
                    {
                        "name": "FGYMNAME",
                        "content": "Your gym"
                    }
                ]
            }
        ]
    }
}

The Mandrill API docs also have JSON examples, which you can use for comparison. Here's a link to the JSON for the messages/send-template: https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top