2017-09-27 19 views
1

をメンバーを追加するとき、私はthe following resourcePOST要求を送信し、私はwhat the error meansを理解し、それでもときに、同じリソースの作品へGET要求、私はそれを取得していますなぜわからないよ400を取得しています。ここで400不正な要求MailChimpリストへ

/lists/{list_id}/members 

は、コードの抜粋です:あなたはqueryパラメータでPOSTリクエストを送信している

$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' => '[email protected]', 
      'email_type' => 'html', 
      'status'  => 'subscribed', 
     ] 
    ]); 

dd($response->getStatusCode()); 

応答

Client error: `POST https://XXXX.api.mailchimp.com/3.0/lists/XXXX/members?email_address=donnie%40test.com&email_type=html&status=subscribed` 
resulted in a `400 Bad Request` 
response: { 
    "type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/", 
    "title": "Invalid Resource", 
    "status": 400, 
    "detail": "The resource submitted could not be validated. For field-specific details, see the 'errors' array.", 
    "instance": "f32e7076-b970-4f5c-82c6-eec5875e83b4", 
    "errors": [{ 
    "field": "", 
    "message": "Schema describes object, NULL found instead" 
    }] 
} 
+0

回答全体を表示できますか?これは、通常、ユーザーが既にリストに登録されている(登録解除されている)場合に発生します。 –

+0

応答が投稿に追加されます。 – Donnie

+0

フォーマットを修正できますか?私はレスポンスで 'detail'インデックスを探しています。 –

答えて

2

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' => '[email protected]', 
      'email_type' => 'html', 
      'status'  => 'subscribed', 
     ] 
    ]); 

dd($response->getStatusCode()); 
関連する問題