I want to subscribe an user to a Mailchimp list as soon as their account is activated I want to subscribe an user to a Mailchimp list as soon as their account is activated. I've created a module to use hook_user_presave() and am trying to call mailchimp_subscribe_user() after that.

function mymodule_user_presave(&amp;$edit, $account, $category) {
  if ($account-&gt;uid // user is not new
      &amp;&amp; $account-&gt;status === "0" &amp;&amp; $edit['status']==1) { // user is being activated
        $list_id = 1;
        $list = mailchimp_get_list($list_id);
        $mergevars = mailchimp_lists_load_user_mergevars($account, $list);

        watchdog('mymodule_log', 'account-&gt;uid '.$account-&gt;uid);
        watchdog('mymodule_log', 'list-&gt;id '.$list_id);

        mailchimp_subscribe_user($list, $account-&gt;mail, $mergevars, FALSE);

        watchdog('mymodule_log', 'got this far!');
  }
}


$account-uid has a valid value and so does $list_id. The problem that does show is up is this 

Notice: Trying to get property of non-object in mailchimp_subscribe_user() 
            (line 103 of .../sites/all/modules/mailchimp/mailchimp.module).
Notice: Trying to get property of non-object in mailchimp_subscribe_user() 
            (line 105 of .../sites/all/modules/mailchimp/mailchimp.module).
Notice: Trying to get property of non-object in mailchimp_subscribe_user() 
            (line 116 of .../sites/all/modules/mailchimp/mailchimp.module).


The lines-

$double_optin = $list-&gt;settings['doublein']; //line 103

$success = $mcapi-&gt;listSubscribe($list-&gt;mc_list_id, $email, $merge_vars, 'html', $double_optin, TRUE);  //line 105

mailchimp_cache_clear_user($list-&gt;mc_list_id, $email); //line 116


And is there any better way to achieve this?
Try below code ... You are missing 5th argument in mailchimp_subscribe_user

function mymodule_user_presave(&amp;$edit, $account, $category) {
  if ($account-&gt;uid // user is not new
      &amp;&amp; $account-&gt;status === "0" &amp;&amp; $edit['status']==1) { // user is being activated

        $mcapi = mailchimp_get_api_object();
        $list_id = 1;
        $list = mailchimp_get_list($list_id);
        $mergevars = mailchimp_lists_load_user_mergevars($account, $list);

        watchdog('mymodule_log', 'account-&gt;uid '.$account-&gt;uid);
        watchdog('mymodule_log', 'list-&gt;id '.$list_id);

        mailchimp_subscribe_user($list, $account-&gt;mail, $mergevars, TRUE, $mcapi);

        watchdog('mymodule_log', 'got this far!');
  }
}