views:

131

answers:

1

I'm using MailChimp's API to subscribe email to a list. Function listsubscribe() is used for email subscription:

public static  listSubscribe(string apikey, string id, string email_address, array merge_vars, string email_type, boolean double_optin, boolean update_existing, boolean replace_interests, boolean send_welcome)

I downloaded MailChimp's official .NET wrapper for their API

When looking in Visual Studio, this is one of overloaded functions:

listSubscribe(string apikey, string id, string email_address, MCMergeVar[] merges)

When I click on definition of MCMergeVar[], this comes out:

[XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct MCMergeVar
    {
        public string name;
        public bool req;
        [XmlRpcMissingMapping(MappingAction.Error)]
        public string tag;
        public string val;
    }

In a php example on MailChimp's website, this is how merges variable is declared:

$merge_vars = array('FNAME'=>'Test', 'LNAME'=>'Account', 'INTERESTS'=>'');

How to write this array correctly for my C# wrapper? I tried something like this:

MCMergeVar[] subMergeVars = new MCMergeVar[1];
subMergeVars["FNAME"] = "Test User";

But it requires an int in place where "FNAME" is now placed, so this doesn't work...

Thanks in advance, Ile

EDIT 1: I tried FoxFire's solution but no data from subMergeVars is passed to MailChimp server, only email is passed:

// Subscribe email to list
            string subID = "26973e52cc";
            string subEmail = "[email protected]";
            MCMergeVar[] subMergeVars = new MCMergeVar[5];
            subMergeVars[0].name = "FNAME";
            subMergeVars[0].val = "FNDynamic";
            subMergeVars[1].name = "LNAME";
            subMergeVars[1].val = "LNDynamic";

            mailChimp.api.listSubscribe(subID, subEmail, subMergeVars, "html");
+1  A: 

Most likely:

MCMergeVar[] subMergeVars = new MCMergeVar[1]; 
subMergeVars[0].name = "FNAME"; 
subMergeVars[0].val = "Test User"; 
Foxfire
It looks ok to me, but data is still not passed to MailChimp server... I will now edit my question with example I tried
ile
I figured it out... .name needs to be replaced with .val and it works just fine :)Thanks!
ile
Its not clear what you mean by ".name needs to be replaced with .val".Could you post a snippet?
Leon van der Walt