Search code examples
phpemailmailjet

how to update template or campaign status to draft or programmed in mailjet


I use mailjet in my php program to send mails to my receivers. I use templates (or known as campaigns) as content of my mail. My code is ..

$ch         =   curl_init();
$content    =   "https://api.mailjet.com/v3/REST/newsletter/3594662/send";
curl_setopt($ch, CURLOPT_URL,$content);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FTPLISTONLY, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_USERPWD, "myapi:mypassword");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
$server_output1 = curl_exec ($ch);
# Close curl process
curl_close ($ch);

Note: I am hardcoding the template id (id:3594662) in my program. And the problem is .. Once i sent a mail , that template's status will change to "sent". So if i send another mail using the same template(id:3594662) i will get error message like this:

"errmessage": "Newsletter has to be in status draft or programmed",
"statuscode": "400

Please help me how to update the status of template to "draft or programmed".. Advance Thanks for the replies..


Solution

  • I'm leading Developers Relations at Mailjet. Thanks for having chosen us to power your email!

    As far as I see, there is a confusion about the role of the newsletter API resource. This resource represents a single newsletter / campaign object in the system, not a re-usable template as you're expecting. This is a feature we're working on and which will be live in few weeks from now.

    In your case, you will need to re-create the newsletter from scratch, following our API guide, like you're already doing I guess.

    Sorry about the inconvenience. Please remain confident that we're working on improving this ASAP.

    Hope this helps!