pacely/mailchimp-api-v3

Reusing the Mailchimp object throws a Bad Request error

Closed this issue · 1 comments

This works:

$this->mc = new \Mailchimp\Mailchimp($this->apiKey);
$lists = $this->mc->request('lists',array(
        'count' => 100,
        'fields'=>'lists.id,lists.name'
    ),'GET');
var_dump($lists);

$this->mc = new \Mailchimp\Mailchimp($this->apiKey);
$lists2 = $this->mc->request('lists',array(
        'count' => 100,
        'fields'=>'lists.id,lists.name'
    ),'GET');
var_dump($lists2);

Re-initializing the Mailchimp object for each call doesn't seem like it should be necessary, though? This fails:

$lists = $this->mc->request('lists',array(
        'count' => 100,
        'fields'=>'lists.id,lists.name'
    ),'GET');
var_dump($lists);

$lists2 = $this->mc->request('lists',array(
        'count' => 100,
        'fields'=>'lists.id,lists.name'
    ),'GET');
var_dump($lists2);

Here's the exception thrown:

Fatal error:  Uncaught exception 'Exception' with message '<HTML><HEAD>
<TITLE>Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reference&#32;&#35;7&#46;116c1160&#46;1436314067&#46;0
</BODY>
</HTML>

Re-initializing just the client object by adding this just before the "try" on line 67 of Mailchimp.php seems to fix it:

$this->client = new Client();

Perhaps Guzzle doesn't really intend the client object be reusable? I don't know enough about Guzzle or GitHub to feel confident just throwing this into your project, but maybe you can take a look?