This is how @Miles M. answer translates to MailChimp API 3.0 (language independence, links to Postman and PHP examples are given below).
Prepare all MailChimp stuff according to my explanation here, except for step 4.
This explanation applies to the case where you want MailChimp to send fully flexible content, providing all the email markup yourself through the API, without using the MailChimp template (neither its pre-encoded, nor the one you wrote yourself).
Step 4 will be replaced by the following instructions. This describes a use case where you want to populate certain parts of your own custom template with dynamic data provided by the API before sending the campaign to which this template is assigned.
So let's get down to this.
Create an empty MailChimp HTML template and add the following HTML code there (simplified)
<div mc:edit="mytext">Mytext should come here from the API call</div>
Now:
- Save, exit, and reopen to see that the MailChimp template validator has wrapped your markup, usually it should have HTML tags.
- See this Mailchimp manual for an explanation of why the
mc:edit="mytext" should be added to the HTML tag, and how to add your own mc:something attributes.
Dynamically set the contents of the above <div> template marked with the mc:edit="mytext" attribute by sending an API request (suppose it uses a non- mc:edit="mytext" language tool, such as Postman, to execute requests and view responses)
Make a request to the campaign update endpoint with a URL such as https://<dc>.api.mailchimp.com/3.0//campaigns/<your_campaign_id>/content and the body of the JSON request, for example:
{ "template": { "id":29345, "sections": { "mytext": "<p>This is my text set via the the API request</p>" } } }
You see, there you have to replace the template id created in step 2 (get the list of templates with this API request , find the answer you need in the answer and find the identifier or find it in the MailChimp web interface when you hover over the template name in the template list in the bottom the browser line will show the identifier at the end of the URL)
Then send the request. In the response, you will see the campaign email in its HTML form (as well as plain text) with your <div> provided with internal HTML "mytext" from the contents of your JSON key "mytext" , namely <div><p>This is my text set via the the API request</p></div>
Of course, you can replace the contents of the "mytext" key "mytext" dynamic markup.
Therefore, you can add another HTML container tag with a different attribute, for example, mc:edit="myotherdynamicdata" to the template, then add the "myotherdynamicdata" JSON key to the request body, fill it with the contents of another dynamic HTML and send the request again. Then look at the body of the response to see that your dynamic information is set there.
You should now send the campaign. Look at the explanations in clause 1 above, starting with clause 6. As you distribute the campaign, your subscribers will see dynamic parts embedded through the content of editable content areas, dynamically set via the API.
As notes for other use cases:
You do not need an API to post new posts from your blog. MailChimp does this automatically, see this guide , you just need to provide a link to the RSS feed from your blog. He will check for new messages and send the campaign template.
For WoprPress users who want to send custom newsletters, when creating the MailChimp automation task as described above, provide MailChimp with an RSS link to your RSS feed with a custom http://www.mywordpresssite.com/feed/?post_type=my_custom_post_type type provided by WordPress by default, for example, http://www.mywordpresssite.com/feed/?post_type=my_custom_post_type
Examples of how to make MailChimp API requests through Postman, authorization example and through PHP, adding content through editable areas .
EDIT after @urwaCFC the question is in the comments below: how to use mc: edit in the mc: repeatable block.
In the experiment, I could not create a template with the mc:edit tags embedded in the mc:repeatable and mc:variant blocks (using the layout of the MailChimp example (see the "Repeating Content Area" section) linked here to update via the CallChimp update template API call. ,
source share