Getting the content of the campaign

Occasional Contributor

Getting the content of the campaign

Seems nothing I do in this API gets me the actual email html. What can I do to pull the email content onto a page in my site. Archive purposes. I've got the listing no problem.

Occasional Contributor

Re: Getting the content of the campaign

Using C# examples.


Re: Getting the content of the campaign

Hy Tyler,


In order to grab the the HTML from an email using our API it would have to be a custom coded email.  I created an example for you in C# so you can see how to grab the data.  If the email was created with the visual editor, then it wouldn't return anything.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Xml;
using System.Xml.XPath;

namespace WebApplication4
    public partial class _Default : System.Web.UI.Page
        string xmlResponse = "";
        string apiKey = "your-api-key";
        string username = "your-user-name";
        string password = "your-password";
        string name = "";
        const string EmailElementName = "EmailContent";

        protected void Page_Load(object sender, EventArgs e)


        protected void getData_btn_Click(object sender, EventArgs e)
            xmlResponse_lbl.Text = getRequest();

        private string getRequest()
            // Remeber to add using
            // Create login creditials
            CredentialCache LoginCredentials = new CredentialCache();

            //Add a new credential for this account
            LoginCredentials.Add(new Uri("{username}"),
                "Basic", // Authentication Type
                new NetworkCredential(apiKey + '%' + username, password));

            // Create the request, you can not new.  All requests must be created with WebRequest.Create
            // Use our URI that we want to get
            WebRequest Request = WebRequest.Create("{username}/campaigns/{CampaignID}");

            // Set Request credentials
            Request.Credentials = LoginCredentials;

            // Place in a try block to ensure that any errors are caught
                //Get resposne from server
                HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();

                //Get our Data
                StreamReader reader = new StreamReader(Response.GetResponseStream());
                XmlTextReader xmlreader = new XmlTextReader(reader);
                XPathDocument doc = new XPathDocument(xmlreader);

                // initialize navigator
                XPathNavigator pn = doc.CreateNavigator();
                string ConstantNamespace = @"";
                string AtomNamespace = @"";
                // initialize namespace manager
                XmlNamespaceManager resolver = new XmlNamespaceManager(pn.NameTable);
                resolver.AddNamespace("at", AtomNamespace);
                resolver.AddNamespace("cc", ConstantNamespace);
                const string xpathSelect = @"//cc:Campaign";
                XPathExpression expr = pn.Compile(xpathSelect);

                XPathNodeIterator nodes = pn.Select(expr);
                while (nodes.MoveNext())
                    // save current node
                    XPathNavigator node = nodes.Current;

                    if (node.HasChildren)

                            switch (node.Name)
                                case EmailElementName:
                                    name = node.Value;

                            }// End Switch
                        } while (node.MoveToNext());
                    } // End do While

                } // End while nodes.MoveNext


                return name;


            catch (WebException e)
                // Web Exception
            catch (Exception e)
                // Exception

            // Parse the Data with XPATH
            return name;

 Please let me know if I can be of any more assistance. 



Ryan Davis
Quality Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

Read More