REST Email Marketing API Documentation

Example 4 — Add to a workflow

Workflows in Symphonie can be triggered by many different conditions: polling from a segment, a new recipient added to the system, an open or click-through, adding to an Offline Event, or by explicitly adding a recipient using the API. This example demonstrates adding a recipient to an existing, known workflow. Workflows can be configured to allow a recipient to enter only one time, to allow multiple entries for the same recipient once the workflow has completed, or to allow the recipient to be in the workflow many times simultaneously. The API will report an error if the recipient cannot be inserted.

Adding a recipient to a workflow triggers the workflow to immediately begin processing the steps for that recipient.

private class wfRecipientAddStatus
{
	public System.Collections.Generic.List<string> notInDatabase = new System.Collections.Generic.List<string>();
	public System.Collections.Generic.List<string> duplicateInFile = new System.Collections.Generic.List<string>();
	public System.Collections.Generic.List<string> currentlyInWorkflow = new System.Collections.Generic.List<string>();
	public System.Collections.Generic.List<string> previouslyInWorkflow = new System.Collections.Generic.List<string>();
}

private static void RestExample4(System.Collections.Generic.List<string> emailAddresses)
{
	try
	{
		string url = "http://www.example.com/api/rest/Workflows/Add";

		System.Text.StringBuilder sb = new StringBuilder();

		sb.Append("{'accountName':'acme', 'login':'ApiUser', 'password':'dfbdsf7udf5dfg78dfs', 'workflowName':'API Add Test','emailAddresses':[");

		sb.AppendFormat("'{0}'", emailAddresses[0]);

		for (int loop = 1; loop < emailAddresses.Count; loop++)
			sb.AppendFormat(", '{0}'", emailAddresses[loop]);

		sb.Append("]}");

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

		string results;

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

		if (results[0] == '[')
		{
			System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
			wfRecipientAddStatus rd = jss.Deserialize<wfRecipientAddStatus>(results);

			foreach (string row in rd.notInDatabase)
				System.Console.WriteLine(row + " is not in the database");

			foreach (string row in rd.previouslyInWorkflow)
				System.Console.WriteLine(row + " has already been in the workflow");

			foreach (string row in rd.duplicateInFile)
				System.Console.WriteLine(row + " was duplicated in the input");
		}
		else
			System.Console.WriteLine(results);
	}
	catch ( System.Exception e )
	{
		System.Diagnostics.Debug.Fail(e.Message);
	}
}

						
# encoding: utf-8
require 'rest-client'
require 'json'

emails = ["bert@example.com","joe@example.com","Pdhhdffgd", "joe@example.com"]

url = "http://www.example.com/api/rest/Workflows/Add"
data = {"accountName":"acme", "login":"ApiUser", "password":"sfgdfgh45wthbf", "workflowName":"API Add Test",
        'emailAddresses':[]}

data["emailAddresses"] = emails

resp = RestClient.post url, data.to_json, {"Content-Type": "application/json"}
if resp.code != 200
    puts "Add to workflow failed!"
    puts resp.code
    return
end

if resp.body[0] == "{"
    data = JSON.parse resp.body
    for row in data["notInDatabase"]
        puts row + " in not in the database"
	end
    for row in data["previouslyInWorkflow"]
        puts row + " has already been in the workflow"
	end
    for row in data["duplicateInFile"]
        puts row + " was duplicated in the input"
	end
else
    puts resp.text
end
import requests
import json


def workflows(emails = []):
    url = "http://www.example.com/api/rest/Workflows/Add"
    data = {"accountName":"acmew", "login":"ApiUser", "password":"xdhw6w7ehd56wg", "workflowName":"API Add Test",
            'emailAddresses':[]}
    
    data["emailAddresses"] += emails

    resp = requests.post(url, json=data, headers={"Content-Type": "application/json"})
    if resp.status_code != 200:
        print "Add to workflow failed!"
        print resp.status_code
        return
    if resp.text[0] == "[":
        data = json.loads(resp.text)
        for row in data["notInDatabase"]:
            print row + " is not in the database"
        for row in data["previouslyInWorkflow"]:
            print row + " has already been in the workflow"
        for row in data["duplicateInFile"]:
            print row + " was duplicated in the input"
    else:
        print resp.text

workflows(["joe@example.com","sam@example.com","Pdhhdffgd", "sam@example.com"])

Share this: