Try our conversational search powered by Generative AI!

Philipp Gaska
Jun 21, 2021
  1740
(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
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024