SaaS CMS has officially launched! Learn more now.

Philipp Gaska
Jun 21, 2021
  1826
(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
Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default,...

Nahid | Jul 16, 2024

Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024

GetNextSegment with empty Remaining causing fuzzes

Optimizely CMS offers you to create partial routers. This concept allows you display content differently depending on the routed content in the URL...

David Drouin-Prince | Jul 8, 2024 | Syndicated blog