Skip to content
Advertisement

What the template_content should be in case that template itself has no need for it (eg template has no mc:edit)?

I replaced the mandrill/mandrill package with mailchimp/transactional. Also I have a tamplate named MYTEMPLATE-001-GR with mergevar name.

And I try to send an email using that template:

<?php
require_once '/path/to/MailchimpTransactional/vendor/autoload.php';

$mailchimp = new MailchimpTransactionalApiClient();
$mailchimp->setApiKey('YOUR_API_KEY');

$message = [
  'subject' => 'Lorem Ipsum',
  'from_email' => 'user@example.com',
  'from_name'  => 'Example User',
  'to'   => 'user@example.com'
  'global_merge_vars' => ['name'=>'Chuck Norris'],
  'track_opens' => true,
  'track_clicks' => true
];

$response = $mailchimp->messages->sendTemplate([
    "template_name" => "MYTEMPLATE-001-GR",
    "template_content" => [[]],
    "message" => $message,
]);
print_r($response);

But the response is the following:

"""
HTTP/1.1 500 Internal Server Errorrn
server: nginx/1.4.6 (Ubuntu)rn
date: Tue, 22 Jun 2021 13:51:38 GMTrn
content-type: application/json; charset=utf-8rn
transfer-encoding: chunkedrn
access-control-allow-origin: *rn
access-control-allow-methods: POST, GET, OPTIONSrn
access-control-allow-headers: Content-Typern
access-control-allow-credentials: falsern
rn
{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a template_content value"}
"""

Meaning I should provide some value in template_content but my template has NO input fields just merge vars therefore I do not know what value needs to be provided in this case.

The previous version it just used NULL as template content value and worked just fine. Do you know how I can change the call into the later version?

Advertisement

Answer

In this case the template_content based upon this tweet for the sendTemplate Mandrill APi call should contain the following values:

 'template_content'=>[["name"=>'','content'=>'']],

Therefore your code should be the following:

require_once '/path/to/MailchimpTransactional/vendor/autoload.php';

$mailchimp = new MailchimpTransactionalApiClient();
$mailchimp->setApiKey('YOUR_API_KEY');

$message = [
  'subject' => 'Lorem Ipsum',
  'from_email' => 'user@example.com',
  'from_name'  => 'Example User',
  'to'   => 'user@example.com'
  'global_merge_vars' => ['name'=>'Chuck Norris'],
  'track_opens' => true,
  'track_clicks' => true
];

$response = $mailchimp->messages->sendTemplate([
    "template_name" => "MYTEMPLATE-001-GR",
    "template_content"=>[["name"=>'','content'=>'']],
    "message" => $message,
]);
print_r($response);

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement