November Happy Hour will be moved to Thursday December 5th.

Philipp Gaska
Sep 29, 2021
  1443
(1 votes)

Sending automated order confirmations via Optimizely Campaign

In this blog post, I want to give you a basic example on how to automatically send an order confirmation via Optimizely Campaign. A transactional mail serves as template for the order confirmation which you can create either via the Optimizely Campaign user interface or the REST API.

Processing order data

When a customer registers in your web shop and completes a purchase order, you collect the data (including information such as product item and price) and store it in JSON format: {"item":"Boots","price":"49.99"}.

You transmit this data together with other recipient data into a dedicated field of the transactional mail's recipient list. You can also store the whole HTML content and different language versions in the transaction recipient list to use only one transactional mail as template instead of creating multiple versions. 

Creating field functions

To access the individual variables within the JSON object and directly insert them into the mailing text, create a field function that refers to the dedicated recipient list field.

The following sample velocity field function replaces the whole mailing content of the transactional mail and refers to the "order" recipient list field which contains the order data:

#set ($jsonContent = $json.readFromString($!{user.data.order}))
Dear customer,
<br/>
Thank you for your purchase! You successfully completed the order of <b>${jsonContent.item}</b> and already paid the full amount of <b>${jsonContent.price} Euro</b>. You will receive another confirmation email as soon as your order has been shipped.
<br/>
Best regards,
<br/>
Your web shop team
<br/>

Converting prices

If you store prices in cent amounts and want to convert them to decimal amounts (e.g., 4999 cents to 49.99 euros), you can use the following function:

#macro(priceConverter $value)$!{null}#set($int=0)$!{null}#set($netto=$int.parseInt($value))$!{null}#set($netto=$StringHelper.percentage(10000, $netto, 2, $Common.locale("de", "", "")))$!{null}$netto$!{null}#end

Displaying JSON objects as HTML text

If you have a JSON array with multiple items and prices, for example, "order":[{"item":"Boots","price":4999},{"item":"Books","price":1299}], and want to display each of them as HTML text, you can use the following function:

#foreach($data in $jsonContent.order)
<h2>$data.item</h2></br>
Price: #priceConverter($data.price) &Euro;</br></br>
#end
Tip: For more information about field functions, see the Optimizely User Guide.

Sending the order confirmation

To transmit the order data and send the order confirmation, use the POST​/{clientId}​/transactionalmail​/{transactionalMailId}​/send operation.

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 Optimizely Campaign under Administration > API Overview > REST API.
  • Transactional mail ID. The ID of the transactional mail that serves as template for the order confirmation. You can find the transactional mail ID in Optimizely Campaign under Campaigns > Transactional Mails.
  • Recipient list ID. The ID of the transaction recipient list. You can find the recipient list ID in Optimizely Campaign under Administration > API Overview > Recipient Lists.
  • Recipient ID. The customer’s email address.
  • Data. The order data to be displayed in the order confirmation.

 The request in curl looks as follows:

curl -X POST "https://api.campaign.episerver.net/rest/123456789/transactionalmail/987654321/send" 
-H "Authorization: BASIC k783r3fjn989dhnfjjdr83dgds1383NDfv=" 
-d "data.order=%7B%22item%22%3A%22Boots%22%2C%22price%22%3A%2249.99%22%7D&recipientListId=238312130812&recipientId=customer%40example.com"

The transactional mail contains only the field function and looks as follows when the order confirmation is sent:

Dear customer,

Thank you for your purchase! You successfully completed the order of Boots and already paid the full amount of 49.99 Euro. You will receive another confirmation email as soon as your order has been shipped.

Best regards,

Your web shop team
Sep 29, 2021

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

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