Change a MailChimp Campaign Name

May 7, 2010 at 6:18 PM

Hi There,

I am checking out the MailChimp api and can't figure out how to change a campaign name after replicating it.  The cro.retult.ToString() is the replicated campaign cid and the schedule code below works fine.  I am not sure if you can name it when replicating but didn't see that.

Thanks for the help.

            campaignReplicateInput cri = new campaignReplicateInput();
            cri.apikey = apikey;
            cri.cid = campaignID

            campaignReplicateOutput cro = new campaignReplicateOutput(cri);
            campaignReplicate cr = new campaignReplicate(cri);
            cro = cr.Execute();
            this.lblcrOutput.Text = cro.result.ToString();

            campaignScheduleInput csi = new campaignScheduleInput();
            csi.cid = cro.result.ToString();
            csi.apikey = apikey;
            DateTime date1 = new DateTime(2010, 5, 8, 8, 30, 52);
            csi.schedule_time = date1;
            campaignSchedule cs = new campaignSchedule(csi);
            cs.Execute();

           //this does not rename the campaign

            campaignUpdateInput cui = new campaignUpdateInput();
            cui.apikey = apikey;
            cui.name = "REPLEN 3 05082010";
            cui.cid = cro.result.ToString();
            campaignUpdate cu = new campaignUpdate(cui);
            cu.Execute();

 


Coordinator
May 8, 2010 at 10:37 AM
Edited May 8, 2010 at 10:59 AM
The MailChimp api method campaignReplicate() only duplicates the campaign, any & all changes to the newly created campaign uses campaignUpdate() or one of the other methods
Regarding, your code....
// ====================================================
//this does not rename the campaign

            campaignUpdateInput cui = new campaignUpdateInput();
            cui.apikey = apikey;
            cui.name = "REPLEN 3 05082010";
            cui.cid = cro.result.ToString();
            campaignUpdate cu = new campaignUpdate(cui);
            cu.Execute();

// ======================================================

The campaignUpdate() method works a little differently than the others; what it's looking for is a set of name/value pairs that are the 'name of the value' to change and the 'new value'

the above code would need to be ...

// change campaign title
//
            campaignUpdateInput cui = new campaignUpdateInput();
            cui.apikey = apikey;
            cui.name = "title";
            cui.value = "REPLEN 3 05082010";
            cui.cid = cro.result.ToString();
            campaignUpdate cu = new campaignUpdate(cui);
            cu.Execute();

// ==============================================

Your version of the code would have returned an error of...

312 - Can not update unknown option "REPLEN 3 05082010"

... you might want to check the error messages after the api calls.

The output of every cmd.Execute() includes a generic List of errors (api_ErrorMessages) .
A count > 0 indicates either an api method returned an error message, or a program execution error occurred.