Error: Call to a member function request() on string in Mailchimp\MailchimpLists->getMemberInfo()

Created on 19 October 2023, 8 months ago
Updated 20 October 2023, 8 months ago

Problem/Motivation

Upgrading to version 2.x causes PHP Error and can't query member info.

Steps to reproduce

Install version 2.2.2 and run the following code

      $config = Drupal::config('mailchimp.settings');
      $api_key = $config->get("api_key");
      $mailChimpLists = new MailchimpLists($api_key);
      $listID = '123456789';
      $email = 'myemail@gmail.com';
      $member = $mailChimpLists->getMemberInfo($listID, $email);

Response code should be 200 if user is found, or 404 if not found. Instead, PHP error returned

Error: Call to a member function request() on string in Mailchimp\MailchimpLists->getMemberInfo()

Proposed resolution

The version 1.x runs return $this->request(...) when checking member info.

But version 2.2.2 runs return $this->api_class->request(...) and fails on the api_class variable.

Remaining tasks

The 2.2.2 code is now in the vendor folder of mailchimp. Should I be calling getMemberInfo() differently, or is there a bug here?

User interface changes

None.

API changes

TBD

Data model changes

None

πŸ› Bug report
Status

Closed: works as designed

Version

2.2

Component

API

Created by

πŸ‡¨πŸ‡¦Canada sagesolutions

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sagesolutions
  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡¨πŸ‡¦Canada sagesolutions

    After reading the docs for mailchimp at https://github.com/thinkshout/mailchimp-api-php, it turns out the way you pass in the api_key has changed in version 3.0. Now you pass in an authentication array to get the api_class variable, then pass that into the MailchimpLists.

          $config = Drupal::config('mailchimp.settings');
          $api_key = $config->get("api_key");
    
          // Instantiate MailchimpApiInterface
          $authentication_settings = [
            'api_key' => $api_key,
            'api_user' => 'api_key',
          ];
          
          // Use Mailchimp class for api_key.
          $api_class = new Mailchimp($authentication_settings);
    
          $mailChimpLists = new MailchimpLists($api_class);
          $listID = '123456789';
          $email = 'myemail@gmail.com';
          $member = $mailChimpLists->getMemberInfo($listID, $email);
    
Production build 0.69.0 2024