Mailchimp-api-php - another broken API request

Created on 1 June 2023, over 1 year ago
Updated 16 January 2024, 10 months ago

Problem/Motivation

There is a bug in the latest release of thinkshout/mailchimp-api-php which causes broken API requests for some api classes (specifically MailchimpLists, which extends MailchimpApiUser).

The bug is present with drupal/mailchimp v2.2.1 and thinkshout/mailchimp-api-php v3.0.0.

This bug is also present with the fix in place for 🐛 Update mailchimp-api-php ASAP to fix broken API requests Fixed (which uses thinkshout/mailchimp-api-php v3.0.0-rc6). (I originally reported it in #3353670-3: Update mailchimp-api-php ASAP to fix broken API requests ).

Steps to reproduce

Make an API request directly using MailchimpLists using ::request.

EG:

<?php
$api_key='xyz';
$mc = new Mailchimp\MailchimpLists($api_key);
$list_id='abc';
$segments = $mc->getSegments($list_id);
?>

This will result in the error:

Error: Call to a member function request() on string in /xxx/yyy/zzz/vendor/thinkshout/mailchimp-api-php/src/MailchimpLists.php on line 595 #0 /xxx/yyy/zzz/web/mctest.php(6): Mailchimp\MailchimpLists->getSegments()

Line 595 of MailchimpLists.php is:

return $this->api_class->request('GET', '/lists/{list_id}/segments', $tokens, $parameters);

So, it looks like a problem with $this->api_class - it contains a string rather than an object. I put in place some logging, and discovered that the string it contains is the API key.

(If the code were executing successfully, the result would be: 401: API Key Invalid.)

Proposed resolution

Update thinkshout/mailchimp-api-php to fix the problem, then update the composer dependency for drupal/mailchimp to use the revised version of the library.

🐛 Bug report
Status

Closed: works as designed

Version

2.0

Component

API

Created by

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

Comments & Activities

Production build 0.71.5 2024