Embed JSON feeds into your campaign

twisted1919

Administrator
Staff member
Starting with MailWizz EMA 1.3 you can embed JSON feeds into you campaigns easily.
In order to take advantage of this feature, when you create a campaign, you will have to enable the feature.
Next, in the campaign template, you will have to add a set of tags that MailWizz EMA will recognize and transform into the actual content of the feed.

Here is a brief example of what you will have to add inside your campaign template to make use of this feature:

HTML:
<!DOCTYPE HTML>
<html>
<head>
   <meta http-equiv="content-type" content="text/html" />
   <title>JSON FEEDS</title>
</head>
<body>
    [JSON_FEED_BEGIN url='http://www.mailwizz.com.com/json-feed.php' count='5']
        <table>
            <tr>
                <td>
                    <a href="[JSON_FEED_ITEM_LINK]">
                        <img src="[JSON_FEED_ITEM_IMAGE]" width="100" height="100"/>
                    </a>
                </td>
                <td>
                    <strong>[JSON_FEED_ITEM_TITLE]</strong><br />
                    <p>[JSON_FEED_ITEM_DESCRIPTION]</p>
                </td>
            </tr>
        </table>
    [JSON_FEED_END]
</body>
</html>

The [JSON_FEED_BEGIN] tag accepts two arguments, url and count.
The url is, well, the url of the feed and the count is the number of items you want to receive back from the feed.

Below is a list with all the tags accepted for JSON feeds:
[JSON_FEED_ITEM_TITLE] - The item title (the title of a product for example)
[JSON_FEED_ITEM_DESCRIPTION] - Short item description
[JSON_FEED_ITEM_CONTENT] - Item content
[JSON_FEED_ITEM_IMAGE] - The image of the item
[JSON_FEED_ITEM_LINK] - The url/permalink to the item
[JSON_FEED_ITEM_PUBDATE] - Item publish date
[JSON_FEED_ITEM_GUID] - Item guid.

All the above tags will work if the feed is valid and the content they try to replace exist in the feed.
You should test your feed campaign before sending, to make sure the tags are parsed and the content is fine because the parsing is strict, any minor error will stop parsing the tags and render them without transformation.
 
@Jose Vega - No this is not possible because the campaign is actually running before the feed is parsed.

A couple of questions:
- What happens if the feed returns less items than specified in "count"?
- When is the feed fetched (i.e. at the start of the campaign once?)
- What happens if the campaign starts and the feed returns an error (i.e. anything but HTTP-200?)
- Is there any way to put "custom data" into the feed (i.e. JSON_FEED_ITEM_PRICE)
 
@bidorbuy - the xml/json feed implementation is really really basic.
- What happens if the feed returns less items than specified in "count"?
Doesn't matter, it will load whatever it finds.

- When is the feed fetched (i.e. at the start of the campaign once?)
At the start of the campaign yes, when first subscriber gets processed. And it is cached to be fetched for the rest of the subscribers from cache directly.

- What happens if the campaign starts and the feed returns an error (i.e. anything but HTTP-200?)
There's no safety mechansim in place, most likely it will send with empty content.

- Is there any way to put "custom data" into the feed (i.e. JSON_FEED_ITEM_PRICE)
No, but as i said, the xml/json feeds are really simple, so nothing stops you to use existing known tags to load different content type from the feed. You can have your feed output a formatted price and a title as "JSON_FEED_ITEM_TITLE" and so on.

Hope it helps.
 
@bidorbuy - the xml/json feed implementation is really really basic.

Doesn't matter, it will load whatever it finds.

Thanks for your response. I think for us it would then perhaps be better to write our own cron which will use the API to update the reoccurring campaign with dynamic product content and in case where there is no data, just pause the campaign.
 
Back
Top