This example shows sending a Document in Symphonie using dynamic substitutions
to mail-merge the contents. We'll assume the content has already been created with multiple
DynamicTags that we'll populate through this API call.
In this example, the HTML table is created in the code. This is for example purposes only, as you would
certainly want to style this table and make other changes.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
private static async Task RestExample6(
HttpClient client,
List<string> topics,
string brandName,
string email)
{
var htmlTable = new StringBuilder("<table><tbody><tr><td>Topic name</td><td>Status</td></tr>");
foreach (string topic in topics)
htmlTable.Append("<tr><td>").Append(topic).Append("</td><td>Subscribed</td></tr>");
htmlTable.Append("</tbody></table>");
var body = new
{
accountName = "acme",
login = "ApiUser",
password = "YOUR_PASSWORD",
documentName = "Welcome1",
emailAddress = email,
substitutions = new Dictionary<string, string>
{
["HtmlTable"] = htmlTable.ToString(),
["brandName"] = brandName
}
};
using (HttpResponseMessage response =
await client.PostAsJsonAsync("https://example.com/API/Rest/Documents/Queue", body))
{
response.EnsureSuccessStatusCode();
string result = await response.Content.ReadAsStringAsync();
if (result.StartsWith("Success"))
Console.WriteLine("Document queued to be sent.");
else
Console.WriteLine("Error: " + result);
}
}
# encoding: utf-8
require 'rest-client'
require 'json'
topics = ["Apple news", "Samsung news"]
brandName = "TechTips.com"
email = "joe@example.com"
htmlTable = "<table><tbody><tr><td>Topic name</td><td>Status</td></tr></tbody>"
for row in topics
htmlTable += "<tr><td>" + row + "</td><td>Subscribed</td></tr>"
end
htmlTable += "</table>"
url = "https://example.com/api/rest/Documents/Queue"
data = {"accountName":"acme", "login":"ApiUser", "password":"YOUR_PASSWORD", "documentName":"Welcome1",
"emailAddress":email,"substitutions":{"HtmlTable":htmlTable, "brandName":brandName}}
resp = RestClient.post url, data.to_json, {"Content-Type": "application/json"}
if resp.code != 200
puts "Document send failed!"
puts resp.code
exit
end
if resp.body != "Success"
puts "An error occurred"
puts resp.body
exit
end
import requests
import json
def sendDocument(topics, brandName, email):
htmlTable = "<table><tbody><tr><td>Topic name</td><td>Status</td></tr></tbody>"
for row in topics:
htmlTable += "<tr><td>" + row + "</td><td>Subscribed</td></tr>"
htmlTable += "</table>"
url = "https://example.com/api/rest/Documents/Queue"
data = {"accountName":"acme", "login":"ApiUser", "password":"YOUR_PASSWORD", "documentName":"Welcome1",
"emailAddress":email,"substitutions":{"HtmlTable":htmlTable, "brandName":brandName}}
resp = requests.post(url, json=data, headers={"Content-Type": "application/json"})
if resp.status_code != 200:
print("Document send failed!")
print(resp.status_code)
return
if resp.text != "Success":
print("An error occurred")
print(resp.text)
return
sendDocument(["Apple news", "Samsung news"], "TechTips.com", "joe@example.com")