2016-11-25 103 views
0

當我執行Guzzle請求時,它第一次使用Laravel,Guzzle和Mailchimp,所以我已經接近咬住我的手指了。我不明白我在做這件事時做錯了什麼。有人能幫助我嗎?Laravel + Guzzle + MailChimp - 400 Bad Request

$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

我認爲你的標題格式不正確(請參閱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' => '[email protected]', 
        'status' => 'subscribed' 
       ] 
     ]); 
     echo $res->getStatusCode(); 
     echo $res->getBody(); 
+0

不起作用,得到了同樣的結果。當我想要檢索數據時,我的標題工作,所以我認爲這不是問題 –