0

I get a 400 Bad Request when I do the Guzzle request, its the first time using Laravel, Guzzle and Mailchimp so I'm close to bite my fingers off. I don't understand what I'm doing wrong on this one. Can somebody help me?

$mailchimp = new Client(['base_uri' => 'https://us14.api.mailchimp.com/3.0/']);

$checkEmail = $mailchimp->request('POST', 'lists/ID/members/', [
        'headers' => [ 'Authorization' => 'apikey ' . config('globals.mailchimp_key') ],
        'json' => [
            'email_address' => $this->email,
            'status' => 'subscribed'
        ]
    ]);
return $checkEmail;
ekad
  • 14,436
  • 26
  • 44
  • 46
Bruno Teixeira
  • 565
  • 4
  • 11
  • 25

1 Answers1

0

I think your header isn't formatted correctly (see the docs). Try this way rather:

            $client = new \GuzzleHttp\Client();
            $res = $client->request('POST',       'https://us8.api.mailchimp.com/3.0/lists/6f0984e55f/members/', [
            'auth' => ['apikey', 'xxxxxxxxxxxxxx-us14'],
                'json' => [
                    'email_address' => 'example@example.com',
                    'status' => 'subscribed'
                ]
        ]);
        echo $res->getStatusCode();
        echo $res->getBody();  
tuesdaye
  • 31
  • 1
  • 4