I'm trying to autogenerate a campaign draft with MailJet api v3
- 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
- In my php code I'm testing with :
$tId=829886; $products=[ ["name"=>'Product1','price'=>'free'], ['name'=>'Product2','price'=>'1 mil'] ];
- 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]);
- 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