{"id":13439767,"url":"https://github.com/drewm/mailchimp-api","last_synced_at":"2025-04-29T18:32:52.641Z","repository":{"id":9786624,"uuid":"11761227","full_name":"drewm/mailchimp-api","owner":"drewm","description":"Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP","archived":false,"fork":false,"pushed_at":"2022-11-14T18:05:47.000Z","size":160,"stargazers_count":1988,"open_issues_count":65,"forks_count":501,"subscribers_count":88,"default_branch":"master","last_synced_at":"2025-04-09T01:22:47.640Z","etag":null,"topics":["mailchimp","mailchimp-api","mailchimp-api-wrapper","mailchimp-php","php","wrapper"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bitpay/bitcore-build","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drewm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-30T09:16:36.000Z","updated_at":"2025-03-19T01:30:04.000Z","dependencies_parsed_at":"2022-07-08T03:45:19.168Z","dependency_job_id":null,"html_url":"https://github.com/drewm/mailchimp-api","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fmailchimp-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fmailchimp-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fmailchimp-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewm%2Fmailchimp-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drewm","download_url":"https://codeload.github.com/drewm/mailchimp-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251560291,"owners_count":21609172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mailchimp","mailchimp-api","mailchimp-api-wrapper","mailchimp-php","php","wrapper"],"created_at":"2024-07-31T03:01:16.938Z","updated_at":"2025-04-29T18:32:52.622Z","avatar_url":"https://github.com/drewm.png","language":"PHP","readme":"MailChimp API\n=============\n\nSuper-simple, minimum abstraction MailChimp API v3 wrapper, in PHP.\n\nI hate complex wrappers. This lets you get from the MailChimp API docs to the code as directly as possible.\n\nRequires PHP 5.3 and a pulse. Abstraction is for chimps.\n\n[![Build Status](https://travis-ci.org/drewm/mailchimp-api.svg?branch=master)](https://travis-ci.org/drewm/mailchimp-api)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/drewm/mailchimp-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/drewm/mailchimp-api/?branch=master)\n[![Packagist](https://img.shields.io/packagist/dt/drewm/mailchimp-api.svg?maxAge=2592000)](https://packagist.org/packages/drewm/mailchimp-api)\n\nInstallation\n------------\n\nYou can install mailchimp-api using Composer:\n\n```\ncomposer require drewm/mailchimp-api\n```\n\nYou will then need to:\n* run ``composer install`` to get these dependencies added to your vendor directory\n* add the autoloader to your application with this line: ``require(\"vendor/autoload.php\")``\n\nAlternatively you can just download the `MailChimp.php` file and include it manually:\n\n```php\ninclude('./MailChimp.php'); \n```\n\nIf you wish to use the batch request or webhook interfaces, you'll also need to download and include the `Batch.php` or `Webhook.php` files:\n\n```php\ninclude('./Batch.php'); \ninclude('./Webhook.php'); \n```\n\nThese are optional. If you're not using batches or webhooks you can just skip them. You can always come back and add them later.\n\nExamples\n--------\n\nStart by `use`-ing the class and creating an instance with your API key\n\n```php\nuse \\DrewM\\MailChimp\\MailChimp;\n\n$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');\n```\n\nThen, list all the mailing lists (with a `get` on the `lists` method)\n\n```php\n$result = $MailChimp-\u003eget('lists');\n\nprint_r($result);\n```\n\nSubscribe someone to a list (with a `post` to the `lists/{listID}/members` method):\n\n```php\n$list_id = 'b1234346';\n\n$result = $MailChimp-\u003epost(\"lists/$list_id/members\", [\n\t\t\t\t'email_address' =\u003e 'davy@example.com',\n\t\t\t\t'status'        =\u003e 'subscribed',\n\t\t\t]);\n\nprint_r($result);\n```\n\nUpdate a list member with more information (using `patch` to update):\n\n```php\n$list_id = 'b1234346';\n$subscriber_hash = MailChimp::subscriberHash('davy@example.com');\n\n$result = $MailChimp-\u003epatch(\"lists/$list_id/members/$subscriber_hash\", [\n\t\t\t\t'merge_fields' =\u003e ['FNAME'=\u003e'Davy', 'LNAME'=\u003e'Jones'],\n\t\t\t\t'interests'    =\u003e ['2s3a384h' =\u003e true],\n\t\t\t]);\n\nprint_r($result);\n```\n\nRemove a list member using the `delete` method:\n\n```php\n$list_id = 'b1234346';\n$subscriber_hash = MailChimp::subscriberHash('davy@example.com');\n\n$MailChimp-\u003edelete(\"lists/$list_id/members/$subscriber_hash\");\n```\n\nQuickly test for a successful action with the `success()` method:\n\n```php\n$list_id = 'b1234346';\n\n$result = $MailChimp-\u003epost(\"lists/$list_id/members\", [\n\t\t\t\t'email_address' =\u003e 'davy@example.com',\n\t\t\t\t'status'        =\u003e 'subscribed',\n\t\t\t]);\n\nif ($MailChimp-\u003esuccess()) {\n\tprint_r($result);\t\n} else {\n\techo $MailChimp-\u003egetLastError();\n}\n```\n\nBatch Operations\n----------------\n\nThe MailChimp [Batch Operations](http://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-batch-operations/) functionality enables you to complete multiple operations with a single call. A good example is adding thousands of members to a list - you can perform this in one request rather than thousands.\n\n```php\nuse \\DrewM\\MailChimp\\MailChimp;\nuse \\DrewM\\MailChimp\\Batch;\n\n$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');\n$Batch \t   = $MailChimp-\u003enew_batch();\n```\n\nYou can then make requests on the `Batch` object just as you would normally with the `MailChimp` object. The difference is that you need to set an ID for the operation as the first argument, and also that you won't get a response. The ID is used for finding the result of this request in the combined response from the batch operation.\n\n```php\n$Batch-\u003epost(\"op1\", \"lists/$list_id/members\", [\n\t\t\t\t'email_address' =\u003e 'micky@example.com',\n\t\t\t\t'status'        =\u003e 'subscribed',\n\t\t\t]);\n\n$Batch-\u003epost(\"op2\", \"lists/$list_id/members\", [\n\t\t\t\t'email_address' =\u003e 'michael@example.com',\n\t\t\t\t'status'        =\u003e 'subscribed',\n\t\t\t]);\n\n$Batch-\u003epost(\"op3\", \"lists/$list_id/members\", [\n\t\t\t\t'email_address' =\u003e 'peter@example.com',\n\t\t\t\t'status'        =\u003e 'subscribed',\n\t\t\t]);\n```\n\nOnce you've finished all the requests that should be in the batch, you need to execute it.\n\n```php\n$result = $Batch-\u003eexecute();\n```\n\nThe result includes a batch ID. At a later point, you can check the status of your batch:\n\n```php\n$MailChimp-\u003enew_batch($batch_id);\n$result = $Batch-\u003echeck_status();\n```\n\nWhen your batch is finished, you can download the results from the URL given in the response. In the JSON, the result of each operation will be keyed by the ID you used as the first argument for the request.\n\nWebhooks\n--------\n\n**Note:** Use of the Webhooks functionality requires at least PHP 5.4.\n\nMailChimp [webhooks](http://kb.mailchimp.com/integrations/other-integrations/how-to-set-up-webhooks) enable your code to be notified of changes to lists and campaigns.\n\nWhen you set up a webhook you specify a URL on your server for the data to be sent to. This wrapper's Webhook class helps you catch that incoming webhook in a tidy way. It uses a subscription model, with your code subscribing to whichever webhook events it wants to listen for. You provide a callback function that the webhook data is passed to.\n\nTo listen for the `unsubscribe` webhook:\n\n```php\nuse \\DrewM\\MailChimp\\Webhook;\n\nWebhook::subscribe('unsubscribe', function($data){\n\tprint_r($data);\n});\n```\n\nAt first glance the _subscribe/unsubscribe_ looks confusing - your code is subscribing to the MailChimp `unsubscribe` webhook event. The callback function is passed as single argument - an associative array containing the webhook data.\n\nIf you'd rather just catch all webhooks and deal with them yourself, you can use:\n\n```php\nuse \\DrewM\\MailChimp\\Webhook;\n\n$result = Webhook::receive();\nprint_r($result);\n```\n\nThere doesn't appear to be any documentation for the content of the webhook data. It's helpful to use something like [ngrok](https://ngrok.com) for tunneling the webhooks to your development machine - you can then use its web interface to inspect what's been sent and to replay incoming webhooks while you debug your code.\n\nTroubleshooting\n---------------\n\nTo get the last error returned by either the HTTP client or by the API, use `getLastError()`:\n\n```php\necho $MailChimp-\u003egetLastError();\n```\n\nFor further debugging, you can inspect the headers and body of the response:\n\n```php\nprint_r($MailChimp-\u003egetLastResponse());\n```\n\nIf you suspect you're sending data in the wrong format, you can look at what was sent to MailChimp by the wrapper:\n\n```php\nprint_r($MailChimp-\u003egetLastRequest());\n```\n\nIf your server's CA root certificates are not up to date you may find that SSL verification fails and you don't get a response. The correction solution for this [is not to disable SSL verification](http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/). The solution is to update your certificates. If you can't do that, there's an option at the top of the class file. Please don't just switch it off without at least attempting to update your certs -- that's lazy and dangerous. You're not a lazy, dangerous developer are you?\n\nIf you have **high-level implementation questions about your project** (\"How do I add this to WordPress\", \"I've got a form that takes an email address...\") please **take them to somewhere like StackOverflow**. If you think you've found a bug, or would like to discuss a change or improvement, feel free to raise an issue and we'll figure it out between us.\n\nContributing\n------------\n\nThis is a fairly simple wrapper, but it has been made much better by contributions from those using it. If you'd like to suggest an improvement, please raise an issue to discuss it before making your pull request.\n\nPull requests for bugs are more than welcome - please explain the bug you're trying to fix in the message.\n\nThere are a small number of PHPUnit unit tests. Unit testing against an API is obviously a bit tricky, but I'd welcome any contributions to this. It would be great to have more test coverage.\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewm%2Fmailchimp-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrewm%2Fmailchimp-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewm%2Fmailchimp-api/lists"}