Want to give dynamic content to MailChimp?

Okay, so I'm going to send a weekly scheduled email with MailChimp. The email should indicate the last 20 of the stock list (garage car stock) to your subscribers.

I can't get this to work with the RSS feed as intended, so I wondered if there is any other way to get the HTML file (in the PHP file) into the body of the MailChimp template weekly?

Thank you very much.

+2
source share
2 answers

If you want to add custom content to a template during posting, I would recommend taking a look at creating a custom template that uses our template language.

If you created a custom template in MailChimp using our template language to specify editable content areas: http://templates.mailchimp.com/getting-started/template-language/ , then you will be able to update these content areas through the API.

To do this, you will want to make either a campaign / create call: https://apidocs.mailchimp.com/api/2.0/campaigns/create.php , or a campaign / update call: https://apidocs.mailchimp.com/api /2.0/campaigns/update.php and specify the section and content that you want to change as part of the content parameter. sections of the content will correspond to the mc: edit tags that have been added to the custom template.

You also have the opportunity to customize your content, for example, adding a name for the greeting in the body of your content, for example, even using merge labels. I also recommend checking them out and considering using them in your content if you need this level of customization: Getting started with Merge tags: http://kb.mailchimp.com/merge-tags/using/getting-started-with -merge-tags

+10
source

This is how @Miles M. answer translates to MailChimp API 3.0 (language independence, links to Postman and PHP examples are given below).

  1. 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.

  2. 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.
  3. 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.

  4. 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. ,

+5
source

Source: https://habr.com/ru/post/1258079/


All Articles