当我发出Guzzle请求时,我收到了400 Bad Request,这是第一次使用Laravel,Guzzle和Mailchimp,所以我很接近我的手指。我不明白我在这个问题上做错了什么。有人可以帮帮我吗?
$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;
答案 0 :(得分:0)
我认为您的标题格式不正确(请参阅docs)。 试试这种方式:
$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();