Error: Class 'MailchimpMarketing\ApiClient'

Viewed 2183

I have the following code

<?php
    require_once('..\..\..\..\..\Users\rodri\vendor\autoload.php');

    $mailchimp = new \MailchimpMarketing\ApiClient();

    $mailchimp->setCOnfig([
            'apiKey' => 'YOUR_API_KEY',
            'server' => 'YOUR_SERVER_PREFIX'
    ]);

    $response = $mailchimp->ping->get();
    print_r($response);
?>

But the local server throws me the following error. And I don't understand why it happens.

Error: Class 'MailchimpMarketing\ApiClient' not found in C:\wamp64\www\Estelio\mailChimp\crearApi\index.php on line 4

Thank you for your help.

3 Answers

It's a bug in the original package caused by a wrong filename.

mailchimp/marketing/lib/Configuration.php should be called ApiClient.php

You could rename it by hand but i would not recommend that. Instead use Phil Cook's fix:

Add this line to your projects composer.json file:

"scripts": { "pre-autoload-dump": "cp ./vendor/mailchimp/marketing/lib/Configuration.php ./vendor/mailchimp/marketing/lib/ApiClient.php" },

Try composer dump-autoload and check again. Btw, please remove your apiKey from your answer. It will be used by the others.

As stated in this pull request, it's required to rename the vendor/mailchimp/marketing/lib/Configuration.php file to vendor/mailchimp/marketing/lib/ApiClient.php, otherwise composer is not able to load the class. After approval, the issue should be fixed. Until then, manually rename the file fixes the problem.

Related