Add Content from URL to template and send campaign using C#

Dec 4, 2012 at 10:29 AM
Edited Dec 4, 2012 at 10:30 AM

Hello all,

I am trying to send a campaign displaying content from a URL.  I can send the campaign using my template but I'm having trouble changing the content of the template. When I send a campaign it only sends the template with no content from my webpage.  I tried to just input text also,  but that did not show either.

Any help would be greatly appreciated

 

{
        Int32 TemplateID = 10321;
        string campaignID = string.Empty;



        // compaign Create Options
        campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
        campaignCreateOpt.list_id = listID;
        campaignCreateOpt.subject = "ALOHATESTER";
        campaignCreateOpt.from_email = "myemail";
        campaignCreateOpt.from_name = "abc";
        campaignCreateOpt.template_id = TemplateID;

        // Content for campaign
        Dictionary content = new Dictionary();
        content.Add("text", "TESTER");
        content.Add("url", "http://thealohacard.com/alohacoupons/print.aspx?couponID=2");

        

        // Conditions
        List csCondition = new List();
        campaignSegmentCondition csC = new campaignSegmentCondition();

        csC.field = "interests-" + 123; 
        csC.op = "all";
        csC.value = "";
        csCondition.Add(csC);

        // 1st Options
        campaignSegmentOptions csOptions = new campaignSegmentOptions();
        csOptions.match = "all";

        // Type Options
        Dictionary typeOptions = new Dictionary();
        typeOptions.Add("offset-units", "days");
        typeOptions.Add("offset-time", "0");
        typeOptions.Add("offset-dir", "after");

        // Create the Campaign

        campaignCreate campaignCreate = new campaignCreate(new campaignCreateInput(apiKey, EnumValues.campaign_type.plaintext, campaignCreateOpt, content, csOptions, typeOptions));
        campaignCreateOutput ccOutput = campaignCreate.Execute();

        List error = ccOutput.api_ErrorMessages;  

        if (error.Count <= 0)
        {
            campaignID = ccOutput.result;
            Label1.Text = campaignID.ToString();
            

        }
        else
        {
            foreach (Api_Error ae in error){
                Label1.Text = "\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error;
            }
        }

        campaignSendNowInput campaignSendNowInput = new campaignSendNowInput("8b05c0ec9d5d8fca47d531b845c6e7e9-us6", campaignID);
        campaignSendNow campaignSendNow = new campaignSendNow(campaignSendNowInput);
        campaignSendNowOutput campaignSendNowOutput = campaignSendNow.Execute();

    }

 

Thanks a lot for the help!

Dec 6, 2012 at 5:06 AM
Edited Dec 6, 2012 at 5:07 AM

Hi ukemasta

Below is a method I have written that is working for me - as you will see I originally had a hard coded URL (now commented out) just to get things working. I have since altered it to read the html code from the web page and submit that to the campaign.

I hope this might help you.

 

public static string createCampaign(int nodeID, string campaignName, string fromName, string fromEmail)
{
campaignCreateInput input = new campaignCreateInput();
input.parms.type = PerceptiveMCAPI.EnumValues.campaign_type.regular;
input.api_Validate = false;
campaignCreateOptions options = new campaignCreateOptions();
options.subject = campaignName;
options.from_email = fromEmail;
options.from_name = fromName;
options.list_id = list_id;
input.parms.options = options;
Dictionary<string, string> content = new Dictionary<string, string>();
content.Add("html", readHTMLPage(nodeID));
//content.Add("url", "http://www.yoyocms.co.nz");
content.Add("text", "Lorem Ipsum");
input.parms.content = content;
campaignCreate cmd = new campaignCreate(input);
campaignCreateOutput ccOutput = cmd.Execute();
return ccOutput.result;
}
private static string readHTMLPage(int nodeID)
{
Node n = new Node(nodeID);
if (n == null)
{
return string.Empty;
}
using (WebClient client = new WebClient ())
{
return client.DownloadString(restExtensions.GetAbsoluteUrl(n.Url));
}
}

The code is specific to Umbraco but trust you can work around that.

Cheers Nigel

Dec 6, 2012 at 5:16 AM

Thank you very much! I will try it now.

what is Umbraco?

does your template have anything that allows you to insert the URL?  Like merge tags or anything?  All I did was use a default template and try to add content.  But after reading a little more,  i might need merge tags or something.

 

Also,  Does this delete all the content in the template and adds the content from the webpage?  I dont understand how the template know where to input that webpage from the URL.

 

ps.  do you have skype?  is so please add me, ukemasta@gmail.com . we can trade code or ask eachother questions. I specialize in a lot of other things besides mailchimp and C#.

 

-ukemasta

Dec 6, 2012 at 5:26 AM

Thank you very much! I will try it now.

what is Umbraco?

does your template have anything that allows you to insert the URL? Like merge tags or anything? All I did was use a default template and try to add content. But after reading a little more, i might need merge tags or something.

Also, Does this delete all the content in the template and adds the content from the webpage? I dont understand how the template know where to input that webpage from the URL.

ps. do you have skype? is so please add me, ukemasta@gmail.com . we can trade code or ask eachother questions. I specialize in a lot of other things besides mailchimp and C#.

-ukemasta



On Wed, Dec 5, 2012 at 8:06 PM, MrNigeW <notifications@codeplex.com> wrote:

From: MrNigeW

Hi ukemasta

Below is a method I have written that is working for me - as you will see I originally had a hard coded URL (now commented out) just to get things working. I have since altered it to read the html code from the web page and submit that to the campaign.

I hope this might help you.

public static string createCampaign(int nodeID, string campaignName, string fromName, string fromEmail)
{
campaignCreateInput input = new campaignCreateInput();
input.parms.type = PerceptiveMCAPI.EnumValues.campaign_type.regular;
input.api_Validate = false;
campaignCreateOptions options = new campaignCreateOptions();
options.subject = campaignName;
options.from_email = fromEmail;
options.from_name = fromName;
options.list_id = list_id;
input.parms.options = options;
Dictionary<string, string> content = new Dictionary<string, string>();
content.Add("html", readHTMLPage(nodeID));
//content.Add("url", "http://www.yoyocms.co.nz");
content.Add("text", "Lorem Ipsum");
input.parms.content = content;
campaignCreate cmd = new campaignCreate(input);
campaignCreateOutput ccOutput = cmd.Execute();
return ccOutput.result;
}
private static string readHTMLPage(int nodeID)
{
Node n = new Node(nodeID);
if (n == null)
{
return string.Empty;
}
using (WebClient client = new WebClient ())
{
return client.DownloadString(restExtensions.GetAbsoluteUrl(n.Url));
}
}

The code is specific to Umbraco but trust you can work around that.
Cheers
Nigel

Read the full discussion online.

To add a post to this discussion, reply to this email (PerceptiveMCAPI@discussions.codeplex.com)

To start a new discussion for this project, email PerceptiveMCAPI@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Dec 6, 2012 at 5:47 AM

Hi ekemasta

umbraco is a ASP.NET Content Management System - www.umbraco.com

Within that I have fully coded an html page that is suitable for use in html based email campaigns.

I do not use prebuilt templates within mailchimp - all html output is hand crafted by myself...

Sorry I am not a skype user.

Cheers, Nigel

Dec 6, 2012 at 5:56 AM
hi MrNigeW,

I will download and use umbraco. You created a template using umbraco, then it displays everything from that webpage in the campaign? is there a specific item in umbraco that you need to add in order to input custom content from C#? What I dont understand is when you send a campaign, how does it know where in the email to add that custom content to. Can you help me understand?


Thanks for all the help,

ukemasta


On Wed, Dec 5, 2012 at 8:48 PM, MrNigeW <notifications@codeplex.com> wrote:

From: MrNigeW

Hi ekemasta

umbraco is a ASP.NET Content Management System - www.umbraco.com

Within that I have fully coded an html page that is suitable for use in html based email campaigns.

I do not use prebuilt templates within mailchimp - all html output is hand crafted by myself...

Sorry I am not a skype user.

Cheers, Nigel

Read the full discussion online.

To add a post to this discussion, reply to this email (PerceptiveMCAPI@discussions.codeplex.com)

To start a new discussion for this project, email PerceptiveMCAPI@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Dec 6, 2012 at 6:23 AM
Hi MrNigeW,

Disregard my last email. I figured it out! I compared my code with yous and I had 1 thing wrong.

Thanks for the help!!!

ukemasta

On Wed, Dec 5, 2012 at 8:56 PM, Doug Chong <dc3hawaii@gmail.com> wrote:
hi MrNigeW,

I will download and use umbraco. You created a template using umbraco, then it displays everything from that webpage in the campaign? is there a specific item in umbraco that you need to add in order to input custom content from C#? What I dont understand is when you send a campaign, how does it know where in the email to add that custom content to. Can you help me understand?


Thanks for all the help,

ukemasta



On Wed, Dec 5, 2012 at 8:48 PM, MrNigeW <notifications@codeplex.com> wrote:

From: MrNigeW

Hi ekemasta

umbraco is a ASP.NET Content Management System - www.umbraco.com

Within that I have fully coded an html page that is suitable for use in html based email campaigns.

I do not use prebuilt templates within mailchimp - all html output is hand crafted by myself...

Sorry I am not a skype user.

Cheers, Nigel

Read the full discussion online.

To add a post to this discussion, reply to this email (PerceptiveMCAPI@discussions.codeplex.com)

To start a new discussion for this project, email PerceptiveMCAPI@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com



Dec 9, 2012 at 7:41 AM
Hi MrNigeW,

Thanks for all your help. I am running into a problem. When converting to html, the pictures do not show up, and the clickable links do not work. Do you know why?

thanks for the help,

ukemasta

On Wed, Dec 5, 2012 at 9:23 PM, Doug Chong <dc3hawaii@gmail.com> wrote:
Hi MrNigeW,

Disregard my last email. I figured it out! I compared my code with yous and I had 1 thing wrong.

Thanks for the help!!!

ukemasta


On Wed, Dec 5, 2012 at 8:56 PM, Doug Chong <dc3hawaii@gmail.com> wrote:
hi MrNigeW,

I will download and use umbraco. You created a template using umbraco, then it displays everything from that webpage in the campaign? is there a specific item in umbraco that you need to add in order to input custom content from C#? What I dont understand is when you send a campaign, how does it know where in the email to add that custom content to. Can you help me understand?


Thanks for all the help,

ukemasta



On Wed, Dec 5, 2012 at 8:48 PM, MrNigeW <notifications@codeplex.com> wrote:

From: MrNigeW

Hi ekemasta

umbraco is a ASP.NET Content Management System - www.umbraco.com

Within that I have fully coded an html page that is suitable for use in html based email campaigns.

I do not use prebuilt templates within mailchimp - all html output is hand crafted by myself...

Sorry I am not a skype user.

Cheers, Nigel

Read the full discussion online.

To add a post to this discussion, reply to this email (PerceptiveMCAPI@discussions.codeplex.com)

To start a new discussion for this project, email PerceptiveMCAPI@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com