APIを使ってMailChimpのリストに登録したいです
開発環境はローカルでMAMPを利用しています。
公式ドキュメント(https://mailchimp.com/developer/guides/create-your-first-audience/)
を見ながら、テストを実施しています。
MailChimpではオーディエンスを作成し、APIキーとリストID取得とできています。
エラーメッセージです
>>php test.php Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://us7.api.mailchimp.com/3.0/lists` resulted in a `403 Forbidden` response: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"User action not permitt (truncated...) in /Applications/MAMP/htdocs/test2/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /Applications/MAMP/htdocs/test2/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /Applications/MAMP/htdocs/test2/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /Applications/MAMP/htdocs/test2/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL) #3 /Applications/MAMP/htdocs/test2/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promi in /Applications/MAMP/htdocs/test2/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113
test.php
1<? 2require_once('vendor/autoload.php'); 3 4$client = new \MailchimpMarketing\ApiClient(); 5 6$client->setConfig([ 7 'apiKey' => '*****************', 8 'server' => 'YOUR_SERVER_PREFIX' 9]); 10 11$list_id = "**********"; 12 13try { 14 $response = $client->lists->addListMember($list_id, [ 15 "email_address" => "prudence.mcvankab@example.com", 16 "status" => "subscribed", 17 "merge_fields" => [ 18 "FNAME" => "Prudence", 19 "LNAME" => "McVankab" 20 ] 21 ]); 22 print_r($response); 23} catch (MailchimpMarketing\ApiException $e) { 24 echo $e->getMessage(); 25}
あなたの回答
tips
プレビュー