Philipp Gaska
Jun 21, 2021
  2014
(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
Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog

ExcludeDeleted(): Prevent Trashed Content from Appearing in Search Results

Introduction In Optimizely CMS, content that is moved to the trash can still appear in search results if it’s not explicitly excluded using the...

Ashish Rasal | Nov 7, 2024

CMS + CMP + Graph integration

We have just released a new package https://nuget.optimizely.com/package/?id=EPiServer.Cms.WelcomeIntegration.Graph which changes the way CMS fetch...

Bartosz Sekula | Nov 5, 2024

Block type selection doesn't work

Imagine you're trying to create a new block in a specific content area. You click the "Create" link, expecting to see a CMS modal with a list of...

Damian Smutek | Nov 4, 2024 | Syndicated blog

.NET 8 FAQ

I have previously written about .NET compatibility in general and .NET 8 in particular, see blog posts here , here and here . With the end of suppo...

Magnus Rahl | Nov 4, 2024

Dynamic packages in Commerce Connect

In Optimizely Commerce Connect, you can group different items using packages and bundles. Package: A package has one or more versions of a product...

K Khan | Nov 1, 2024