Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Richard Terris 273 posts 714 karma points
    Oct 23, 2014 @ 16:14
    Richard Terris
    0

    Campaign Monitor Intergration

    Hi guys,

    Hoping someone can help me with this.

    I've followed this post: http://www.liquidint.com/blog/extending-umbraco-contour-campaign-monitor-integration/ and also the contour development documentation and a few other posts.

    I'm trying to integrate campaign monitor with contour but I'm stuck.

    I have this class which gets a list of lists from campaign monitor and this is working correctly because I can create a campaign monitor prevalue source in contour and it contains my campaign monitor lists:

    namespace MyApp.WebApp.Utils
    {
        public class CampaignMonitorListsFieldSettingsType : FieldSettingType
        {
            private CheckBoxList cbl = new CheckBoxList();
            private string _val = string.Empty;
    
            public override WebControl RenderControl(Umbraco.Forms.Core.Attributes.Setting setting, Form form)
            {
                cbl.ID = setting.GetName();
                cbl.RepeatLayout = RepeatLayout.Flow;
                cbl.CssClass = "cml";
                string apiKey = ConfigurationManager.AppSettings["CampaignMonitorAPIKey"] as string;
                string clientId = ConfigurationManager.AppSettings["CampaignMonitorClientID"] as string;
                AuthenticationDetails authDetails = new ApiKeyAuthenticationDetails(apiKey);
                Client client = new Client(authDetails, clientId);
                IEnumerable<BasicList> lists = client.Lists();
                ListItem li;
                foreach (BasicList list in lists)
                {
                    li = new ListItem(list.Name, list.ListID);
                    cbl.Items.Add(li);
                }
                IEnumerable<string> vals = _val.Split(',');
                foreach (string v in vals)
                {
                    ListItem selLi = cbl.Items.FindByValue(v);
                    if (selLi != null)
                    {
                        selLi.Selected = true;
                    }
                }
    
                return cbl;
            }
        }
    }
    

    When I select any of the lists in the prevalue source and click save, I am getting an error which indicates that my list is empty:

    namespace MyApp.WebApp.Utils
    {
        public class CampaignMonitorExtension : FieldPreValueSourceType
        {
            public CampaignMonitorExtension()
            {
                this.Id = new Guid("9fd33370-2fb6-4fbb-88e2-3d14d2e65772");
                this.Name = "Campaign Monitor Mailing Lists";
                this.Description = "List of mailing lists available within campaign monitor";
            }
    
    
            [Umbraco.Forms.Core.Attributes.Setting("ListsToInclude",
            description = "The selected lists to which the user can subscribe",
            control = "MyApp.WebApp.Utils.CampaignMonitorListsFieldSettingsType",
            assembly = "MyApp.WebApp")]
            public String ListsToInclude { get; set; }
    
    
            public override List<PreValue> GetPreValues(Field field)
            {
    
                List<PreValue> pvs = new List<PreValue>();
                string apiKey = ConfigurationManager.AppSettings["CampaignMonitorAPIKey"] as string;
                string clientId = ConfigurationManager.AppSettings["CampaignMonitorClientID"] as string;
                AuthenticationDetails authDetails = new ApiKeyAuthenticationDetails(apiKey);
                Client client = new Client(authDetails, clientId);
                IEnumerable<BasicList> lists = client.Lists();
                PreValue preValue;
                IEnumerable<string> vals = ListsToInclude.Split(',');
                foreach (string v in vals)
                {
                    BasicList l = lists.FirstOrDefault(s => s.ListID == v);
                    preValue = new PreValue();
                    preValue.Value = l.Name;
                    preValue.Id = l.ListID;
                    pvs.Add(preValue);
                }
                return pvs;
            }
    
            public override List<Exception> ValidateSettings()
            {
                List<Exception> exs = new List<Exception>();
                if (string.IsNullOrEmpty(ListsToInclude))
                {
                    exs.Add(new Exception("Lists To Include is Empty"));
                }
                return exs;
            }
        }
     }
    

    Stepping through the code shows that ListsToInclude and field parameters are both null.

    Since the rendercontrol method returns a checkboxlist, I have tried changing ListsToInclude to CheckboxList instead of string but this has no impact.

    I'm sure this will be something small/silly because this is a first attempt with extending contour for me, but the code DOES seem to make sense so I can't figure out what's wrong.

    Any help will be very much appreciated.

    Richard

  • Tim Geyssens 6419 posts 15052 karma points MVP 2x c-trib
    Oct 24, 2014 @ 10:32
    Tim Geyssens
    0
    foreach(BasicList list in lists)
               
    {
                    li
    =newListItem(list.Name, list.ListID);
                    cbl
    .Items.Add(li);
               
    }

    If you debug does that bit actually add some listitems to the checkboxlist?

     

  • Tim Geyssens 6419 posts 15052 karma points MVP 2x c-trib
    Oct 24, 2014 @ 10:33
    Tim Geyssens
    0

    And code looks ok, but don't have experience with the campaign monitor api so not sure if that is returning any results

  • Richard Terris 273 posts 714 karma points
    Oct 24, 2014 @ 10:42
    Richard Terris
    0

    Morning Tim,

    Thanks for taking a look at this.

    I can confirm that cbl is populated with lists from campaign monitor and the control is rendered with the checkbox list, so it looks like the info is coming back from campaign monitor fine.

    But when we hit the GetPreValues method, both 'field' and 'ListsToInclude' are null.

    I don't think this is a campaign monitor issue, that part seems ok and I've worked with the API in the past.

    Ravi suggested that it may be because the cbl list will contain campaign monitor lists as key value pairs, a list id and a list name, so that ListsToInclude may not be the correct type?

    I tried changing it to CheckboxList but that didn't make any difference

    Richard

  • Tim Geyssens 6419 posts 15052 karma points MVP 2x c-trib
    Oct 24, 2014 @ 10:45
    Tim Geyssens
    100

    Ok spotted the missing link,

    In your FieldSettingType you also need to override

     

    publicoverridestring Value

    That is basicly what is used by Contour to fetch the value from the checkbloxlist so that is why you are getting a null

    some examples: 

    textbox 

    publicoverridestring Value

            {

                get

                {

                    return tb.Text;

                }

                set

                {

                    tb.Text = value;

                }

     

            }

    dropdowlist:

    publicoverridestring Value {

                get {

                    return ddl.SelectedValue;

                }

                set {

                   if(!string.IsNullOrEmpty(value))

                       _val = value;

                }

     

            }

  • Tim Geyssens 6419 posts 15052 karma points MVP 2x c-trib
    Oct 24, 2014 @ 10:50
    Tim Geyssens
    0

    So you'll need to return a comma seperated list of list id's

  • Richard Terris 273 posts 714 karma points
    Oct 24, 2014 @ 11:21
    Richard Terris
    0

    Tim, you are the MAN!!

    I still had a little work to do with the lists but it's all working now.

    So, thank you very very much indeed for your help!

    Do you think once I tidy the code up slightly, this would be useful as a blog post? There does seem to be a lot of posts about CM integration with Contour.

    Thanks again,

    Richard

  • Greg Fyans 112 posts 271 karma points
    Oct 24, 2014 @ 11:51
    Greg Fyans
    1

    It's useful as a blog post if you think it is - do it :)

  • Tim Geyssens 6419 posts 15052 karma points MVP 2x c-trib
    Oct 24, 2014 @ 12:04
    Tim Geyssens
    1

    Yeah defo useful as a blogpost :)

  • Richard Terris 273 posts 714 karma points
    Nov 11, 2014 @ 23:25
    Richard Terris
    0

    Following on from this, I have finally written a blog post. I hope to update some things soon and have a better solution or an actual package.

    In the meantime I hope this is useful:

    http://richardterris.blogspot.co.uk/2014/11/umbraco-contour-campaign-monitor.html

  • Tim Geyssens 6419 posts 15052 karma points MVP 2x c-trib
    Nov 12, 2014 @ 09:34
    Tim Geyssens
    0

    Nice, thanks for sharing!

Please Sign in or register to post replies

Write your reply to:

Draft