2011-06-17 7 views
5

Necesito crear y enviar inmediatamente campañas en MailChimp.com. Usé C# wrapper Percepective MCAPI.dll para este propósito.Cómo crear una campaña en MailChimp usando ASP.Net

del MailChimp API, está claro que no podemos incluir listas, pero podemos crear campañas. Probé el código pero el campaignID is retured null; ninguna excepción lanzada al menos. Establecí el campaigntype to Auto.

aquí es mi fragmento de código:

 
try 
{ 
    string apiKey = "api-us2"; // API KEY is valid 
    string emailAddress = "[email protected]"; 
    listsForEmailInput lstForEmailInput = new listsForEmailInput(apiKey, emailAddress); 
    listsForEmail cmd = new listsForEmail(lstForEmailInput); 
    listsForEmailOutput lstEmailOutPut = cmd.Execute(); 

    List lstResults = lstEmailOutPut.result; 
    string listID = lstResults[0]; // Got Precraeted List ID(Valid Confirmed) 

    Console.WriteLine("\n" + listID);     


    // compaign Create 
    campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); 
    campaignCreateOpt.list_id = listID; 
    campaignCreateOpt.subject = " New Campaign from dev_Anil"; 
    campaignCreateOpt.from_email = "[email protected]"; 
    campaignCreateOpt.from_name = "anil"; 

    Dictionary content = new Dictionary(); 
    content.Add("html", "Helloaasdsa"); 
    content.Add("text", "Hi all !! this is dev_anil"); 
    content.Add("url", ""); 
    content.Add("archive", ""); 

    campaignSegmentOptions csOptions = new campaignSegmentOptions(); 
    csOptions.match = "any"; // Could not set Condition -- need help for this 

    // Need to set a Dictionary typeOptions because null is not supported 
    Dictionary typeOptions = new Dictionary(); 

    campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.auto, campaignCreateOpt, content, csOptions, typeOptions); 
    campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms); 
    campaignCreate campaignCreate = new campaignCreate(campaignCreateInput); 
    campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput); 
    string abc = ccOutput.result; // This comes out to null 

} 
catch(Exception ee) 
{ 
    Console.WriteLine("\n\n Exception :" + ee.Message); // no exception 
} 

¿Alguien puede mostrar la dirección correcta y lo que está mal con el código.

cualquier ayuda sería muy apreciada.

gracias.

Respuesta

2

He resuelto este problema y aquí está el código como solución. aquí listID es una ID de lista previamente creada en su cuenta en Mailchimp.

 
private void CreateCampaignAndSend(string apiKey, string listID) 
{ 
      Int32 TemplateID = 100; 
      string campaignID =string.Empty;

// compaign Create Options campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); campaignCreateOpt.list_id = listID; campaignCreateOpt.subject = "subject"; campaignCreateOpt.from_email = "[email protected]"; campaignCreateOpt.from_name = "abc"; campaignCreateOpt.template_id = TemplateID; // Content Dictionary<string, string> content = new Dictionary<string, string>(); content.Add("html_ArticleTitle1", "ArticleTitle1"); content.Add("html_ArticleTitle2","ArticleTitle2"); content.Add("html_ArticleTitle3", "ArticleTitle3"); content.Add("html_Article1", "Article1"); content.Add("html_Article2", "Article2"); // Conditions List<campaignSegmentCondition> csCondition = new List<campaignSegmentCondition>(); campaignSegmentCondition csC = new campaignSegmentCondition(); csC.field = "interests-" + 123; // where 123 is the Grouping Id from listInterestGroupings() csC.op = "all"; csC.value = ""; csCondition.Add(csC); // Options campaignSegmentOptions csOptions = new campaignSegmentOptions(); csOptions.match = "all"; // Type Options Dictionary<string, string> typeOptions = new Dictionary<string, string>(); typeOptions.Add("offset-units", "days"); typeOptions.Add("offset-time", "0"); typeOptions.Add("offset-dir", "after"); // Create Campaigns campaignCreate campaignCreate = new campaignCreate(new campaignCreateInput(apiKey, EnumValues.campaign_type.plaintext, campaignCreateOpt, content, csOptions, typeOptions)); campaignCreateOutput ccOutput = campaignCreate.Execute(); List<Api_Error> error = ccOutput.api_ErrorMessages; // Catching API Errors if (error.Count <= 0) { campaignID = ccOutput.result; } else { foreach (Api_Error ae in error) { Console.WriteLine("\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error); } } }
+0

en un accound libre me sale: l Error 506: Autoresponders sólo están disponibles en mensual y Pay-as-you-go de cuentas. – Edd

+0

pero no puedo obtenerlo de este código donde está este conjunto ... eliminé los valores del diccionario de tipoOpciones pero no fue de allí ... – Edd

+0

hola anl: campaignSegmentCondition me muestra un error en mi compilador vs'13. amablemente muéstrame un camino :( –

1

Eliminé la url y el archivo del contenido. Entonces la campaña fue creada muy bien:

 // campaign Create 
     campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); 
     campaignCreateOpt.list_id = listId; 
     campaignCreateOpt.subject = " New Campaign from Someemone"; 
     campaignCreateOpt.from_email = "[email protected]"; 
     campaignCreateOpt.from_name = "someone"; 


     Dictionary<string, string> content = new Dictionary<string, string>(); 
     content.Add("html", "Lots of cool stuff here."); 


     campaignSegmentOptions csOptions = new campaignSegmentOptions(); 
     csOptions.match = "any"; // Could not set Condition -- need help for this 

     // Need to set a Dictionary typeOptions because null is not supported 
     Dictionary<string,string> typeOptions = new Dictionary<string, string>(); 

     campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.trans, campaignCreateOpt, content, csOptions, typeOptions); 
     campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms); 
     campaignCreate campaignCreate = new campaignCreate(campaignCreateInput); 
     campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput); 
     string newCampaignId = ccOutput.result; // Not null anymore 
Cuestiones relacionadas