1

I'm trying to autogenerate a campaign draft with MailJet api v3

  1. I created a template on their website in MJML, simple one (templateid is $tId=829886;):
 <mj-raw> {% for products in var:product %} </mj-raw>
      <p>{%product.name %}</p>
      <p>{%product.price%}</p>
 <mj-raw>{% endfor %}</mj-raw>

I also included both [[UNSUB_LINK_IT]] and [[UNSUB_LINK_EN]] because of the locale it_IT

  1. In my php code I'm testing with :
$tId=829886;
$products=[
    ["name"=>'Product1','price'=>'free'],
    ['name'=>'Product2','price'=>'1 mil']
];
  1. Campaign draft
$body = [
    'Locale' => "it_IT",
    'Sender' => "MisterMailjet",
    'SenderEmail' => "s.s***i@***.p**",
    'Subject' => "Greetings from Mailjet",
    'ContactsListID' => "13",
    'Title' => "Friday newsletter".uniqid(),
    'EditMode' => 'tool2',
    'TemplateID'=>$tId,
    'Variables' => [
        'products' => $products
    ], ]; 
$response = $mj->post(Resources::$Campaigndraft, ['body' => $body]);
  1. I tried passing 'Variables' to $response = $mj->post(Resources::$CampaigndraftDetailcontent, ['id' => $cId, 'body' => $body]); but I always get

Invalid json input: object ""->"TCampaignDraft" has no property "Variables"

Can someone link or show me an example of a $Campaigndraft or $CampaigndraftDetailcontent where they pass some variables for a loop, I can't seem to find anything online. I'm not sure if it's even possible to pass vars to campaign anymore. Please any help is appreciated

Community
  • 1
  • 1
Cr1xus
  • 427
  • 3
  • 20
  • Checkout the documentation: https://dev.mailjet.com/reference/email/campaigns/drafts/#v3_post_campaigndraft_draft_ID_detailcontent It seems like you should use `MJMLContent` to set the data for the campaign. – Cyclonecode May 10 '19 at 09:05
  • apparently you can't inject vars in campaign.. only in normal emails senders – Cr1xus May 12 '19 at 00:06

1 Answers1

1

Currently the advanced "Template Language" used for personalization, is only available for so called Transactional messages and not for Campaigns. Thus the /campaigndraft resource used to create the Campaign won't recognize the "Variables" or "Vars" properties used to declare the variables within an Send API Call.

Indeed in the guide here you would see that

Mailjet Template language is available for transactional messages only.

From what I know there should be a release for Template Language in Campaigns as well, but that would be with the use of Contact Properties instead of Variables.

I hope that helps.

Krass
  • 86
  • 1
  • 7