Try our conversational search powered by Generative AI!

Philipp Gaska
Jun 21, 2021
  1728
(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
A day in the life of an Optimizely Developer - Enabling Opti ID within your application

Hello and welcome to another instalment of A Day In The Life Of An Optimizely developer, in this blog post I will provide details on Optimizely's...

Graham Carr | May 9, 2024

How to add a custom property in Optimizely Graph

In the Optimizely CMS content can be synchronized to the Optimizely Graph service for it then to be exposed by the GraphQL API. In some cases, you...

Ynze | May 9, 2024 | Syndicated blog

New Security Improvement released for Optimizely CMS 11

A new security improvement has been released for Optimizely CMS 11. You should update now!

Tomas Hensrud Gulla | May 7, 2024 | Syndicated blog

Azure AI Language – Key Phrase Extraction in Optimizely CMS

In this article, I demonstrate how the key phrase extraction feature, offered by the Azure AI Language service, can be used to generate a list of k...

Anil Patel | May 7, 2024 | Syndicated blog