Mailchimp API V3 CodeIgniter Library Integration

By Ralph Vugts on February 9, 2016

Tagged in: , ,

Looking to quickly integrate Mailchimp API V3 with code igniter? I’ve taken this API wrapper and converted it into a library for CI so you can quickly integrate it into your project.

Step 1:

Download this file and add it into your application/libraries folder. On line 185 I have manually overridden the timeout value as it was always timing out when trying to pull lists from Mailchimp.

Step 2:

Add your Mailchimp API key to your config file:

$config['Mailchimp_api_key'] = 'YOUR_KEY_HERE';

Step 3:

Load the library into your controller and add the ID of the list you would like to add a contact to. Eg:

Load the library:


Add the appropriate list id:

$list_id = 'YOUR_LIST_ID';

Make the API call:

$result = $this->mailchimp->post("lists/$list_id/members", [
                'email_address' => '[email protected]',
                'merge_fields' => ['FNAME'=>'Ralph', 'LNAME'=>'Vugts'],
                'status'        => 'subscribed',

Check out the full git repo for more info on other functions.

Need help integrating Mailchimp into your existing website? We can help you! Get in touch and let just know what you are trying to achieve.


Ralph has been developing websites and systems for nearly 20 years. Passionate and curious, he’s an a-typical developer who understands how users interact with the systems he builds. He understands that systems need to be human-friendly. Ralph loves working in an industry that is constantly changing and disrupting itself.

Comments (16)

Add a comment
  • Gabriel   28 Nov 2017
    good day.. please how can I implement and output mailchimp api with codeigniter?
    • Ralph Vugts   5 Jan 2018
      Hi there, did you try the steps in this guide?
  • Justin Jones   23 Jan 2018
    Hi Ralph, Great work! Is there an integration with CI for the batch files and web hook files on the github?
    • Ralph Vugts   21 Feb 2018
      I haven't tried. But should be pretty straightforward if you checkout the Git docs here:
  • Tom   4 Feb 2018
    HI there, How do i use batch on codeigniter?
    • Ralph Vugts   21 Feb 2018
      Check out the Github docs for more info:
  • Nilanjan   27 Feb 2018
    $list_id = 'YOUR_LIST_ID'; What is the LIST ID here???
    • Ralph Vugts   27 Feb 2018
      Check out:
  • Priyanka   27 Feb 2018
    Hi Ralph, i am working with codeigniter and i am just confused with List id where i will put it weather in controller's function or in config file
    • Ralph Vugts   28 Feb 2018
      It needs to go in your controller... or where ever you are making the API call. You can see the $list_id variable being used in the API call itself so needs to be accessible. You could place it in your config if you wanted to... but you would need to modify the API call accordingly.
  • Simon   10 Mar 2018
    Hi Ralph - I've implemented the above just like your steps and while the code doesn't error my update to mailchimp doesnt work. I'm simply trying to post a new user into it. Any tips on how to debug? I'm fairly new to PHP so while I can see some debug steps on the git page I'm not sure how to apply them and step through the code or output errors at the right time as my code is registering a user so redirects as soon as it successful? Any help would be amazing! My Controller code: $this->load->library('MailChimp'); $list_id = 'XXXXXX'; $result = $this->mailchimp->post("lists/" . $list_id . "/members", [ 'email_address' => '[email protected]', 'status' => 'subscribed', ]); print_r($result);
    • Ralph Vugts   11 May 2018
      var_dump out your $result and see what it says.
  • Jedd Saliba   27 Aug 2018
    hi i need help on this. it always say 'Non-existent class: MailChimp' when i load the library to my controller. thanks
  • fazil raza   27 Nov 2018
    really helpful
  • Robert Williams   13 Nov 2019
    Hello.. do you know how i would pass values from a form into the API? Thanks
    • Ralph Vugts   16 Apr 2020
      Take a look at the example under "Make the API call:" you would need to find a way to access the form details. So will depend on what form plugin you are using. Or simply access the variables in $_POST via PHP.

Add a comment

Your email address will not be published. Required fields are marked *