REST Email Marketing API Documentation

Example 6 — Send a Document

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.

private static void RestExample6(System.Collections.Generic.List<string> topics, string brandName, string email)
		string htmlTable = "<table><tbody><tr><td>Topic name</td><td>Status</td></tr></tbody>";

		foreach (string row in topics)
			htmlTable += "<tr><td>" + row + "</td><td>Subscribed</td></tr>";
		htmlTable += "</table>";

		string url = "";

		System.Text.StringBuilder data = new StringBuilder();
		data.Append("{'accountName':'acme', 'login':'ApiUser', 'password':'dfh45ywhhsb', 'documentName':'Welcome1','emailAddress':");
		data.AppendFormat("'{0}'", email);
		data.Append(",'substitutions':{ 'HtmlTable':");
		data.AppendFormat("'{0}'", htmlTable);
		data.AppendFormat(", 'brandName':'{0}'", brandName);

		System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
		request.Method = "POST";
		request.ContentType = "application/json";
		request.ContentLength = data.Length;
		using (Stream webStream = request.GetRequestStream())
			using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))

		string result;

		System.Net.WebResponse webResponse = request.GetResponse();
		using (Stream webStream = webResponse.GetResponseStream())
			using (StreamReader responseReader = new StreamReader(webStream))
				result = responseReader.ReadToEnd();

		if (result.StartsWith("Success"))
			System.Console.WriteLine("Document queued to be sent. You should receive it shortly.");
			System.Console.WriteLine("Error: {0}", result);
	catch ( System.Exception e)
# encoding: utf-8
require 'rest-client'
require 'json'

topics = ["Apple news", "Samsung news"]
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 = ""
data = {"accountName":"acme", "login":"ApiUser", "password":"xvc67ysvd76svdh", "documentName":"Welcome1",
        "emailAddress":email,"substitutions":{"HtmlTable":htmlTable, "brandName":brandName}}
resp = url, data.to_json, {"Content-Type": "application/json"}

if resp.code != 200
    puts "Document send failed!"
    puts resp.code

if resp.body != "Success"
    puts "An error occurred"
    puts resp.body
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 = ""
    data = {"accountName":"acme", "login":"ApiUser", "password":"dfb4w5y4thwrb", "documentName":"Welcome1",
            "emailAddress":email,"substitutions":{"HtmlTable":htmlTable, "brandName":brandName}}
    resp =, json=data, headers={"Content-Type": "application/json"})
    if resp.status_code != 200:
        print "Document send failed!"
        print resp.status_code
    if resp.text != "Success":
        print "An error occurred"
        print resp.text

sendDocument(["Apple news", "Samsung news"], "", "")

Share this: