添加成员到MailChimp列表时400错误请求

时间:2017-09-27 20:30:03

标签: php laravel-5 guzzle mailchimp-api-v3.0

我向the following resource发送POST请求并获得400分。我理解what the error means,但仍不确定为什么我在{{1}时收到该请求请求相同的资源。

GET

以下是代码的一部分:

/lists/{list_id}/members

响应

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', // <-- Drop in a GET here and it works, other than it's not the behavior I need.
    env('MAILCHIMP_API_URL') . 'lists/' . env('MAILCHIMP_LIST_KEY') . '/members',
    [
        'auth'  => ['app', env('MAILCHIMP_API_KEY')],
        'query' => [
            'email_address' => 'donnie@test.com',
            'email_type'    => 'html',
            'status'        => 'subscribed',
        ]
    ]);

dd($response->getStatusCode());

1 个答案:

答案 0 :(得分:2)

您正在发送带有POST个参数的query个请求。您需要发送JSON已编码的正文!

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', // <-- Drop in a GET here and it works, other than it's not the behavior I need.
    env('MAILCHIMP_API_URL') . 'lists/' . env('MAILCHIMP_LIST_KEY') . '/members',
    [
        'auth'  => ['app', env('MAILCHIMP_API_KEY')],
        'json' => [
            'email_address' => 'donnie@test.com',
            'email_type'    => 'html',
            'status'        => 'subscribed',
        ]
    ]);

dd($response->getStatusCode());