Search code examples
asp.netapimailchimpmailchimp-api-v3

integrate mailchimp api in asp.net


I am integrating mailchimp api in asp.net.

web.config:

<add key="APIKey" value="XXXX9dsfij4yZXXXXXXXXXX-XXXX" />

in code

using mailchimp;

IMailChimpManager manager = new MailChimpManager();

when I see what's in 'manager' object, it's null.

how do i get api key from web.config file?


Solution

  • According to: https://github.com/brandonseydel/MailChimp.Net/blob/master/README.md You have two options here.

    First, you can manually read API key from config:

    using mailchimp;
    using System.Configuration;
    
    //Read API key from config
    var apiKey= ConfigurationManager.AppSettings["APIKey"];
    
    IMailChimpManager manager = new MailChimpManager(apiKey);
    

    Second option is that you can change read key to MailChimpApiKey, so change

    <add key="APIKey" value="XXXX9dsfij4yZXXXXXXXXXX-XXXX" />
    

    to

    <add key="MailChimpApiKey" value="XXXX9dsfij4yZXXXXXXXXXX-XXXX" />
    

    In that case you don't need to pass API key:

    using mailchimp;
    
    IMailChimpManager manager = new MailChimpManager();