Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brille24/mailchimp
A simple PHP 7 library to consume the mailchimp API v3.0: https://developer.mailchimp.com/
https://github.com/brille24/mailchimp
api mailchimp mailchimp-api mailchimp-php newsletter newsletter-management php php72
Last synced: about 1 month ago
JSON representation
A simple PHP 7 library to consume the mailchimp API v3.0: https://developer.mailchimp.com/
- Host: GitHub
- URL: https://github.com/brille24/mailchimp
- Owner: Brille24
- Created: 2019-03-21T15:56:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-20T12:48:51.000Z (about 5 years ago)
- Last Synced: 2024-10-12T13:06:09.421Z (about 1 month ago)
- Topics: api, mailchimp, mailchimp-api, mailchimp-php, newsletter, newsletter-management, php, php72
- Language: PHP
- Size: 103 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/Brille24/mailchimp.svg?branch=master)](https://travis-ci.org/Brille24/mailchimp)
## Brille24 Mailchimp Library
This library is a simple package aimed to consume the Mailchimp API v3.0.
## Currently implemented features
* Reading, Creating and Updating Mailchimp Lists
* Reading, Creating and Updating Mailchimp List-Members## Tests
```bash
composer install
php vendor/bin/phpspec run
php vendor/bin/phpstan analyse src/ --level max --configuration phpstan.neon
```## Examples
```php
// Getting all lists
$listRequest = ListRequest::fromMethod(RequestMethod::byName('GET'));
// Getting a specific list
$listRequest = ListRequest::fromMethodAndIdentifier(RequestMethod::byName('GET'), "your_list_id");// Getting all members from a list.
$memberRequest = MemberRequest::fromListAndMethod($listRequest, RequestMethod::byName('GET'));// Getting a specific member of a list.
$memberRequest = MemberRequest::fromListMethodAndEmail(
$listRequest,
RequestMethod::byName('GET'),
'some@email_address.tld'
);/**
* All other requests work in a similar, wrapped style
**/// Updating or creating a new member in a list.
// 1. Make a list and member request.
// 2. Add body parameters.
$bodyParameters = new MemberData();
$bodyParameters->setEmailAddress("some@email_address.tld");
$bodyParameters->setStatus(MemberStatus::byName('PENDING'));
$bodyParameters->setLanguage(MemberLanguage::byName('English'));
// ... there can me more fields in your Mailchimp lists,
$bodyParameters->setMergeFields(['FNAME' => 'Some', 'LNAME' => 'Dude']);
$memberRequest->setBodyParameters($bodyParameters);// Alternatively or additionally, add query parameters to your requests for filtering response data.
/** @var $queryParameters QueryParameters*/
$queryParameters = QueryParameters::fromNative(['fields' => 'email_address', 'count' => 10]);
$memberRequest->setQueryParameters($queryParameters);// Execute Request
$credentials = new Credentials('your_api_key_here');
// This uses the guzzle HTTP client library.
$mailchimp = new Mailchimp(new Client(), $credentials);
try {
$response = $mailchimp->executeRequest($memberRequest);
echo (string) $response->getBody();
} catch (\Throwable $throwable) {
// This throws every exception that guzzle will throw.
}
```