Try our conversational search powered by Generative AI!

Philipp Gaska
Jun 21, 2021
  1702
(0 votes)

Updating mailing content via REST API

In a previous blog post, I gave an example on how to use the Episerver Campaign REST API to create a Smart Campaign and mailing. To update the created mailing with plain text, you can use the POST/{clientId}/smartcampaigns/{campaignId}/messages/{mailingId} operation. 

I recommend using a more convenient operation for updating mailing content. The POST​/{clientId}​/smartcampaigns​/{campaignId}​/messages​/{mailingId}​/content operation lets you update the mailing with plain text, HTML content, or multipart content that consists of HTML and plain text.

Note: You can only update mailings created via REST API.

You need the following information:

  • Client ID. The ID of the client the REST API is set up for. You can find the client ID in Episerver Campaign under Administration > API overview > REST API.
  • Campaign ID. ID of the created Smart Campaign. To get the campaign ID, you can use the GET​/{clientId}​/smartcampaigns operation. You can also find the campaign ID in Episerver Campaign under Campaigns > Smart Campaigns.
  • Mailing ID. ID of the mailing whose content you want to update. To get the mailing ID, you can use the GET​/{clientId}​/smartcampaigns operation. You can also find the mailing ID in Episerver Campaign under Campaigns > Smart Campaigns.

Plain text

To transmit plain text, set the content type to "text/plain" in the request header and transmit the content within the request body. The request in curl looks as follows:

curl -X POST "https://api.campaign.episerver.net/rest/123456789/smartcampaigns/987654321/messages/123454321/content" -H "Authorization: BASIC k783r3fjn989dhnfjjdr83dgds1383NDfv=" -H "Content-Type: text/plain" -d "This is plain text."

HTML content

To transmit HTML content, set the content type to "text/html" in the request header and transmit the content within the request body. The request in curl looks as follows: 

curl -X POST "https://api.campaign.episerver.net/rest/123456789/smartcampaigns/987654321/messages/123454321/content" -H "Authorization: BASIC k783r3fjn989dhnfjjdr83dgds1383NDfv=" -H "Content-Type: text/html" -d "This is <b>HTML</b> content."

Multipart content

Multipart content consists of plain text and HTML text. This is useful if, for example, a web browser is unable to display the HTML content correctly. Instead of displaying the text along with HTML tags, the plain text is displayed. 

To transmit multipart content, transmit the different content parts within the request body as form data without specifying the content type in the request header. The request in curl looks as follows: 

curl -X POST "https://api.campaign.episerver.net/rest/123456789/smartcampaigns/987654321/messages/123454321/content" -H "Authorization: BASIC k783r3fjn989dhnfjjdr83dgds1383NDfv=" -F "content1=This is plain text.;type=text/plain" -F "content2=This is <b>HTML</b> content.;type=text/html"

By default, the ISO-8859-1 charset is used. This charset represents only a limited number of languages. You can also specify a different charset within the request, for example, UTF-8:

curl -X POST "https://api.campaign.episerver.net/rest/123456789/smartcampaigns/987654321/messages/123454321/content" -H "Authorization: BASIC k783r3fjn989dhnfjjdr83dgds1383NDfv=" -H "charset=utf-8" -F "content1=This is plain text.;type=text/plain" -F "content2=This is <b>HTML</b> content.;type=text/html;charset=utf-8"
Jun 21, 2021

Comments

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog