Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP

Overview

MailChimp API

Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP.

I hate complex wrappers. This lets you get from the MailChimp API docs to the code as directly as possible.

Requires PHP 5.3 and a pulse. Abstraction is for chimps.

Build Status Scrutinizer Code Quality Packagist

Installation

You can install mailchimp-api using Composer:

composer require drewm/mailchimp-api

You will then need to:

  • run composer install to get these dependencies added to your vendor directory
  • add the autoloader to your application with this line: require("vendor/autoload.php")

Alternatively you can just download the MailChimp.php file and include it manually:

include('./MailChimp.php'); 

If 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:

include('./Batch.php'); 
include('./Webhook.php'); 

These are optional. If you're not using batches or webhooks you can just skip them. You can always come back and add them later.

Examples

Start by use-ing the class and creating an instance with your API key

use \DrewM\MailChimp\MailChimp;

$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');

Then, list all the mailing lists (with a get on the lists method)

$result = $MailChimp->get('lists');

print_r($result);

Subscribe someone to a list (with a post to the lists/{listID}/members method):

'[email protected]', 'status' => 'subscribed', ]); print_r($result);">
$list_id = 'b1234346';

$result = $MailChimp->post("lists/$list_id/members", [
				'email_address' => '[email protected]',
				'status'        => 'subscribed',
			]);

print_r($result);

Update a list member with more information (using patch to update):

['FNAME'=>'Davy', 'LNAME'=>'Jones'], 'interests' => ['2s3a384h' => true], ]); print_r($result);">
$list_id = 'b1234346';
$subscriber_hash = MailChimp::subscriberHash('[email protected]');

$result = $MailChimp->patch("lists/$list_id/members/$subscriber_hash", [
				'merge_fields' => ['FNAME'=>'Davy', 'LNAME'=>'Jones'],
				'interests'    => ['2s3a384h' => true],
			]);

print_r($result);

Remove a list member using the delete method:

$list_id = 'b1234346';
$subscriber_hash = MailChimp::subscriberHash('[email protected]');

$MailChimp->delete("lists/$list_id/members/$subscriber_hash");

Quickly test for a successful action with the success() method:

'[email protected]', 'status' => 'subscribed', ]); if ($MailChimp->success()) { print_r($result); } else { echo $MailChimp->getLastError(); }">
$list_id = 'b1234346';

$result = $MailChimp->post("lists/$list_id/members", [
				'email_address' => '[email protected]',
				'status'        => 'subscribed',
			]);

if ($MailChimp->success()) {
	print_r($result);	
} else {
	echo $MailChimp->getLastError();
}

Batch Operations

The MailChimp 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.

use \DrewM\MailChimp\MailChimp;
use \DrewM\MailChimp\Batch;

$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');
$Batch 	   = $MailChimp->new_batch();

You 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.

'[email protected]', 'status' => 'subscribed', ]); $Batch->post("op2", "lists/$list_id/members", [ 'email_address' => '[email protected]', 'status' => 'subscribed', ]); $Batch->post("op3", "lists/$list_id/members", [ 'email_address' => '[email protected]', 'status' => 'subscribed', ]);">
$Batch->post("op1", "lists/$list_id/members", [
				'email_address' => '[email protected]',
				'status'        => 'subscribed',
			]);

$Batch->post("op2", "lists/$list_id/members", [
				'email_address' => '[email protected]',
				'status'        => 'subscribed',
			]);

$Batch->post("op3", "lists/$list_id/members", [
				'email_address' => '[email protected]',
				'status'        => 'subscribed',
			]);

Once you've finished all the requests that should be in the batch, you need to execute it.

$result = $Batch->execute();

The result includes a batch ID. At a later point, you can check the status of your batch:

$MailChimp->new_batch($batch_id);
$result = $Batch->check_status();

When 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.

Webhooks

Note: Use of the Webhooks functionality requires at least PHP 5.4.

MailChimp webhooks enable your code to be notified of changes to lists and campaigns.

When 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.

To listen for the unsubscribe webhook:

use \DrewM\MailChimp\Webhook;

Webhook::subscribe('unsubscribe', function($data){
	print_r($data);
});

At 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.

If you'd rather just catch all webhooks and deal with them yourself, you can use:

use \DrewM\MailChimp\Webhook;

$result = Webhook::receive();
print_r($result);

There doesn't appear to be any documentation for the content of the webhook data. It's helpful to use something like ngrok 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.

Troubleshooting

To get the last error returned by either the HTTP client or by the API, use getLastError():

echo $MailChimp->getLastError();

For further debugging, you can inspect the headers and body of the response:

print_r($MailChimp->getLastResponse());

If you suspect you're sending data in the wrong format, you can look at what was sent to MailChimp by the wrapper:

print_r($MailChimp->getLastRequest());

If 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. 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?

If 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.

Contributing

This 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.

Pull requests for bugs are more than welcome - please explain the bug you're trying to fix in the message.

There 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.

Comments
  • Batch put doesn't add member.

    Batch put doesn't add member.

    It seems like the batch put doesn't add any members (update works though). Not sure if it's an issue with MailChimp or with this wrapper.

    Method:

    "lists/{$listID}/members/{$hash}"
    
    opened by Vennik 15
  • API v3 - PATCH: Schema describes array, object found instead

    API v3 - PATCH: Schema describes array, object found instead

    Greetings,

    I am test-driving the Mailchimp API v3 using your wrapper. Let me start by thanking you for making it available.

    I'm getting an error when attempting to update a merge field using PATCH:

    $mc->patch("lists/$mailchimp_list_id/merge-fields/" . $field['merge_id'], $data);
    

    This is the payload (var_dump($json_data); inserted just before curl_exec() call in MailChimp.php):

    {"options":{"choices":{"0":"Aaa","1":"Bbb","2":"Ccc"}},"apikey":"xxxxxx-us5"}
    

    Mailchimp is returning an error, as follows:

    [title] => Invalid Resource
    [status] => 400
    [detail] => The resource submitted could not be validated. For field-specific details, see the 'errors' array.
    [errors] => Array
        (
            [0] => Array
                (
                    [field] => options.choices
                    [message] => Schema describes array, object found instead
                )
        )
    

    I suspect this is caused by use of JSON_FORCE_OBJECT in json_encode(). Not sure why you are using this option.

    As a side note, removing JSON_FORCE_OBJECT yields a different error, but that one is most likely a Mailchimp issue...

    [title] => Bad Request
    [status] => 400
    [detail] => This resource has not yet implemented array assignment for options.choices.
    
    bug 
    opened by dregad 15
  • is already a list member

    is already a list member

    Hi !

    I have two different lists (A & B). It seems i cannot post an email address on list B if it exists on list A.

    $list_id = 'xxxlist_Bxxx';
    $response_array = $MailChimp->post("lists/$list_id/members", [
    	'email_address' => $email,
    	'status'        => 'subscribed'
    ]);
    

    I get this response : "[email protected] is already a list member. Use PUT to insert or update list members."

    When i try a PUT, i get this reponse : "The requested method and resource are not compatible. See the Allow header for this resource's available methods."

    Any idea ?

    Thank you ! Johan

    opened by joSFD 14
  • request_successful = false / Unknown error

    request_successful = false / Unknown error

    Hey @drewm, thanks for this script, it's certainly helped. Up until now I've had no problems using the script to display subscriber counts with the old version, compatible with MailChimp's pre-v3 API. However, I cannot get the new version (for MailChimp 3) to work.

    After I include MailChimp.php, I'm doing the following:

    use \DrewM\MailChimp\MailChimp;
    $MailChimp = new MailChimp('xxxxxxxxxxxxxxxxxxxxxxxxxx-us5');
    $result = $MailChimp->get('lists');
    

    If I try to echo/print the $result variable, I get nothing. If I var_dump it, I get bool(false). If I var_dump($MailChimp), I get the following:

    object(DrewM\MailChimp\MailChimp)#1 (7) { ["api_key":"DrewM\MailChimp\MailChimp":private]=> string(36) "xxxxxxxxxxxxxxxxxxxxxxxxxx-us5" ["api_endpoint":"DrewM\MailChimp\MailChimp":private]=> string(33) "https://us5.api.mailchimp.com/3.0" ["verify_ssl"]=> bool(true) ["request_successful":"DrewM\MailChimp\MailChimp":private]=> bool(false) ["last_error":"DrewM\MailChimp\MailChimp":private]=> string(64) "Unknown error, call getLastResponse() to find out what happened." ["last_response":"DrewM\MailChimp\MailChimp":private]=> array(2) { ["headers"]=> array(20) { ["url"]=> string(40) "https://us5.api.mailchimp.com/3.0/lists?" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0.015) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) } ["body"]=> bool(false) } ["last_request":"DrewM\MailChimp\MailChimp":private]=> array(5) { ["method"]=> string(3) "get" ["path"]=> string(5) "lists" ["url"]=> string(39) "https://us5.api.mailchimp.com/3.0/lists" ["body"]=> string(0) "" ["timeout"]=> int(10) } }

    And of course, note that I've removed my API key in the examples above. The API key is correct in my code, and I even generated a new one just to ensure I had it right.

    Ultimately, I had to settle for this solution, which works perfectly. I have no idea what's preventing your script from working in my case. The PHP version I'm testing on is 5.3.1 and I've enabled cURL in php.ini, which I believe is required.

    Any thoughts on what's going wrong?

    question 
    opened by impressivewebs 14
  • New tags feature

    New tags feature

    Thanks very much for the API - it's working very well for us. Is there any intention to add the new tags feature - replacing segments? Does anyone know ho to do this

    opened by prema770 12
  • bundle cert

    bundle cert

    Basic Debian Jessie basic default cert pool does keeps from connecting to api.mailchimp.com Just bundle the cert for now until the situation got stabilized.

    
    ---
     README.md                          |  2 --
     src/GTE_CyberTrust_Global_Root.pem | 15 +++++++++++++++
     src/MailChimp.php                  |  9 ++-------
     3 files changed, 17 insertions(+), 9 deletions(-)
     create mode 100644 src/GTE_CyberTrust_Global_Root.pem
    
    diff --git a/README.md b/README.md
    index 9f8dae6..045dbc7 100644
    --- a/README.md
    +++ b/README.md
    @@ -158,8 +158,6 @@ If you suspect you're sending data in the wrong format, you can look at what was
     print_r($MailChimp->getLastRequest());
     ` ``
    
    -If 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?
    -
     Contributing
     ------------
    
    diff --git a/src/GTE_CyberTrust_Global_Root.pem b/src/GTE_CyberTrust_Global_Root.pem
    new file mode 100644
    index 0000000..82ae5e1
    --- /dev/null
    +++ b/src/GTE_CyberTrust_Global_Root.pem
    @@ -0,0 +1,15 @@
    +-----BEGIN CERTIFICATE-----
    +MIICWjCCAcMCAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzAJBgNVBAYTAlVTMRgwFgYD
    +VQQKEw9HVEUgQ29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNv
    +bHV0aW9ucywgSW5jLjEjMCEGA1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJv
    +b3QwHhcNOTgwODEzMDAyOTAwWhcNMTgwODEzMjM1OTAwWjB1MQswCQYDVQQGEwJV
    +UzEYMBYGA1UEChMPR1RFIENvcnBvcmF0aW9uMScwJQYDVQQLEx5HVEUgQ3liZXJU
    +cnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMTGkdURSBDeWJlclRydXN0IEds
    +b2JhbCBSb290MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVD6C28FCc6HrH
    +iM3dFw4usJTQGz0O9pTAipTHBsiQl8i4ZBp6fmw8U+E3KHNgf7KXUwefU/ltWJTS
    +r41tiGeA5u2ylc9yMcqlHHK6XALnZELn+aks1joNrI1CqiQBOeacPwGFVw1Yh0X4
    +04Wqk2kmhXBIgD8SFcd5tB8FLztimQIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAG3r
    +GwnpXtlR22ciYaQqPEh346B8pt5zohQDhT37qw4wxYMWM4ETCJ57NE7fQMh017l9
    +3PR2VX2bY1QY6fDq81yx2YtCHrnAlU66+tXifPVoYb+O7AWXX1uw16OFNMQkpw0P
    +lZPvy5TYnh+dXIVtx6quTx8itc2VrbqnzPmrC3p/
    +-----END CERTIFICATE-----
    diff --git a/src/MailChimp.php b/src/MailChimp.php
    index ed6752a..24aa913 100644
    --- a/src/MailChimp.php
    +++ b/src/MailChimp.php
    @@ -15,12 +15,6 @@ class MailChimp
         private $api_key;
         private $api_endpoint = 'https://<dc>.api.mailchimp.com/3.0';
    
    -    /*  SSL Verification
    -        Read before disabling: 
    -        http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
    -    */
    -    public $verify_ssl = true;
    -
         private $last_error = '';
         private $last_response = array();
         private $last_request = array();
    @@ -188,10 +182,11 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = 10
                 'Content-Type: application/vnd.api+json',
                 'Authorization: apikey ' . $this->api_key
             ));
    +        curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/GTE_CyberTrust_Global_Root.pem');
             curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)');
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    -        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
    +        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
             curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
             curl_setopt($ch, CURLOPT_ENCODING, '');
             curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    -- 
    2.1.4
    
    
    please excuse the inline diff, I had to add a space between two backquote that appear inside README.md hunk.
    
    opened by drzraf 12
  • Resource Not Found error from MailChimp when trying to patch a new subscriber

    Resource Not Found error from MailChimp when trying to patch a new subscriber

    Hi - thanks for providing this wrapper. I'm upgrading from the v2.0 wrapper, and having some trouble doing a simple update. get('lists') works, so connectivity is there, but the following code:

    $MailChimp = new MailChimp('myapicodehere-us12');
    $list_id = '24c23b0042';
    $subscriber_hash = $MailChimp->subscriberHash('[email protected]');
    $result = $MailChimp->patch("lists/$list_id/members/$subscriber_hash", array(
                    'merge_fields' => array('FNAME'=>'Firstname', 'LNAME'=>'Lastname')
                ));
    
    print_r($result);
    
    

    returns following:

    Array ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Resource Not Found [status] => 404 [detail] => The requested resource could not be found. [instance] => )

    I've triple-checked the list_id, and am reasonably confident it is correct - both from checking the MailChimp website, and checking the returned ID from get('lists'). I should point out that due to version issues on my production server, I've had to comment out the namespace - but as noted, this did not seem to effect the get('lists') and as this is test code, there should not be any namespace collisions.

    Any ideas or pointers on what I'm doing wrong would be greatly appreciated!

    opened by krixmeister 11
  • Doesn't Work with PHP 7

    Doesn't Work with PHP 7

    When trying to get lists with PHP 7.0.8, I get the error message Unknown error, call getLastResponse() to find out what happened.. When I call getLastResponse(), I get a blank response. Same exact code works just fine with 5.6.10:

    array(3) {
      ["headers"]=>
      array(26) {
        ["url"]=>
        string(57) "https://us2.api.mailchimp.com/3.0/lists?count=10&offset=0"
        ["content_type"]=>
        NULL
        ["http_code"]=>
        int(0)
        ["header_size"]=>
        int(0)
        ["request_size"]=>
        int(0)
        ["filetime"]=>
        int(-1)
        ["ssl_verify_result"]=>
        int(1)
        ["redirect_count"]=>
        int(0)
        ["total_time"]=>
        float(0.441107)
        ["namelookup_time"]=>
        float(0.419261)
        ["connect_time"]=>
        float(0.429059)
        ["pretransfer_time"]=>
        float(0)
        ["size_upload"]=>
        float(0)
        ["size_download"]=>
        float(0)
        ["speed_download"]=>
        float(0)
        ["speed_upload"]=>
        float(0)
        ["download_content_length"]=>
        float(-1)
        ["upload_content_length"]=>
        float(-1)
        ["starttransfer_time"]=>
        float(0)
        ["redirect_time"]=>
        float(0)
        ["redirect_url"]=>
        string(0) ""
        ["primary_ip"]=>
        string(14) "<redacted>"
        ["certinfo"]=>
        array(0) {
        }
        ["primary_port"]=>
        int(443)
        ["local_ip"]=>
        string(10) "<redacted>"
        ["local_port"]=>
        int(54736)
      }
      ["httpHeaders"]=>
      NULL
      ["body"]=>
      NULL
    }
    ``
    opened by rafecolton 10
  • Re-subscriber

    Re-subscriber

    How can I fix it with this error?

    Array ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Member Exists [status] => 400 [detail] => [email protected] is already a list member. Use PUT to insert or update list members. [instance] => )

    Thanks

    Keith

    opened by kk12837 10
  • Merge fields not working properly with PUT request

    Merge fields not working properly with PUT request

    Hi,

    Thanks for your work, it is working great and very useful !

    I am having an issue though with the PUT request :

    $mc = new MailChimp($api_key);
    $list_id = '123456789'; // not the real one obviously
    $subscriber_hash = $mc->subscriberHash($email);
    $result = $mc->put("lists/$list_id/members/$subscriber_hash", [
       'email_address' => $email,
       'status'        => 'subscribed',
       'merge_fields' => ["FNAME" => $firstname, "LNAME" => $lastname],
       'status_if_new' => 'subscribed'
    ]);
    

    The request works fine by adding a new member to the list or updating one if already existing, but the FNAME merge field is not taken into account... I can assure you the $firstname variable is not empty (I also tried with a fixed string value). The returned array contains the following entry:

    [merge_fields] => Array ( [FNAME] => [LNAME] => DOE )

    The same request using a POST action does work fine, so the FNAME merge field is configured properly on MailChimp side. But I have to use the PUT action since it is the only one allowing a previously deleted email to be added again. I have tried switching the order of the merge fields with no success, the same FNAME field still does not work.

    Can you be of any help or is this a MailChimp-related bug ?

    Thank you in advance !

    opened by onkstudio 9
  • Interests: schema describes boolean, string found instead

    Interests: schema describes boolean, string found instead

    I'm trying to add a subscriber to a list with interest groups. I'm currently using the CocoaRestClient to send the POST call to this library, which then sends to MailChimp via /lists/[listid]/members. My request params are like this:

    email_address: [email protected] status: subscribed merge_fields[FNAME]: first merge_fields[LNAME]: last

    This works. A subscriber is successfully added.

    But when I try to add interests, the request fails. Here's an example array:

    Array(
    	[email_address] => [email protected]
    	[status] => subscribed
    	[merge_fields] => Array(
    		[FNAME] => first
    		[LNAME] => last
    	)
    	[interests] => Array(
    		[myinterestid] => true
    	)
    )
    

    Here is the error result:

    "errors": [
        {
          "field": "interests.myinterestid",
          "message": "Schema describes boolean, string found instead"
        }
      ]
    

    I've tried using this code before sending my $params to the wrapper, as it helped with the merge_fields, but it does not seem to affect the interests:

    foreach ( $params as $key => $value ) {
    	if ( is_array( $value ) ) {
    		foreach ( $value as $subkey => $subvalue ) {
    			if ( 'true' === $subvalue ) {
    				$subvalue = true; // try to force a boolean in case it is a string
    			}
    			$value[ $subkey ] = sanitize_text_field( $subvalue );
    		}
    	} else {
    		$params[ $key ] = sanitize_text_field( $value );
    	}
    }
    
    opened by jonathanstegall 8
  • Create new list $MailChimp->post(

    Create new list $MailChimp->post("lists", [...]);

    Hi, I don`t understand how to create a new List my requet $result = $MailChimp->post("lists", [ "name" => "name", "permission_reminder" => "permission_reminder", "email_type_option" => true, "contact" => [ "company" => "company", "address1" => "address1", "city" => "city", "country" => "country", ], "campaign_defaults" => [ "from_name" => "from_name", "from_email" => "[email protected]", "subject" => "subject", "language" => "language", ],]);

    And i have a error 400 Invalid Resource What the right way to do this request?

    Thanks for answer

    opened by petrkl 0
  • Product variant visibility

    Product variant visibility

    Hello,

    Here is the "visibility" parameter on mailchimp for product variant.

    https://mailchimp.com/developer/marketing/api/ecommerce-product-variants/add-product-variant/

    but no details what values can It take. What should I enter?

    opened by tcagkansokmen 0
  • Add ADDRESS using update_list_member merge fields

    Add ADDRESS using update_list_member merge fields

    I am updating customers using the Python API. I get a successful response, however the response is still an empty string in the address field.

    Python code:

        # mailchimp office address
        address_dict = {
            "addr1": "2015 Main St",
            "addr2": "",
            "city": "Vancouver",
            "state": "BC",
            "country": "Canada",
            "zip": "V5T 3C2",
            }
        merge_fields = {
            'MMERGE7': other_info,
            'MMERGE9': other_info,
            'MMERGE10': other_info,
            'ADDRESS': address_dict,
        }
        try:
            response = client.lists.update_list_member("AUDIENCE_ID", "SUBSCRIBER_HASH", merge_fields)
            print("Succesful Update on", customer['Email'])
            print(response['merge_fields'])
    

    Output of merge fields response

    {'FNAME': '', 
    'LNAME': '', 
    'ADDRESS': '', 
    'PHONE': '', 
    'MMERGE5': '', 
    'MMERGE6': '', 
    'MMERGE7': '', 
    'MMERGE9': 'CUSTOMER_ID', 
    'MMERGE10': 'CUSTOMER NAME', 
    'MMERGE11': '', 
    'MMERGE12': ''}
    

    Am I doing something wrong here?

    opened by peterrwilson99 0
  • Mailchimp Batch bulk update tags not working with PUT method

    Mailchimp Batch bulk update tags not working with PUT method

    Hi,

    I tried to bulk update mailchimp tags using batch method. I used put method to do the same. But it is not working.

    Attaching my code snippet. Please help me out,

    $Batch = $MailChimp->new_batch();

        $list_id = "listID";
        $tagsSelected = ['tagFromAPI 99','tagFromAPI 00'];
    
        $Batch->put("op1", "lists/$list_id/members", [
            'email_address' => '[email protected]',
            'status_if_new'        => 'subscribed',
            'tags'          => $tagsSelected,
            'merge_fields' => [
                             'FNAME' => 'Jish3' ?: '',
                             'LNAME' => 'win' ?: '',
            ]
        ]);
    
        $Batch->put("op2", "lists/$list_id/members", [
                    'email_address' => '[email protected]',
                    'status_if_new'        => 'subscribed',
                    'tags'          => $tagsSelected,
                    'merge_fields' => [
                        'FNAME' => 'Lax2' ?: '',
                        'LNAME' => 'Sav' ?: '',
       ]
                ]);
    
        $Batch->put("op3", "lists/$list_id/members", [
                    'email_address' => '[email protected]',
                    'status_if_new'        => 'subscribed',
                    'tags'          => $tagsSelected,
                    'merge_fields' => [
                        'FNAME' => 'Lenity1' ?: '',
                        'LNAME' => 'Lancer' ?: '',
       ]
                ]);
        
        
        $result = $Batch->execute();
        $MailChimp->new_batch($batch_id);
        $result = $Batch->check_status();
        echo '<pre>';print_r($result);
    
    opened by ashwindas77 0
Releases(v2.5)
  • v2.5(Feb 16, 2018)

  • v2.4(May 9, 2017)

  • v2.2(Apr 23, 2016)

    This release adds a new class Webhook for receiving webhooks from the MailChimp API. It uses a pub/sub model whereby you subscribe to the webhook event with a callback function.

    Source code(tar.gz)
    Source code(zip)
  • v2.0(Jan 17, 2016)

    After developing this in a branch for a while, it's time to make the version of this for MailChimp API v3 the master branch.

    I can't see any reason to carry on with the previous version when MailChimp have deprecated that version of their API, so going forward we're all in on v3. Confusingly that's v2 of this wrapper. What can you do.

    Thanks so much to everyone who has contributed to this release.

    Source code(tar.gz)
    Source code(zip)
Owner
Drew McLellan
Staff Engineer, Front End @snyk. Previously @netlify, lead developer on @PerchCMS and @benotist
Drew McLellan
Simple Curl based wrapper for Binance API for PHP scripts

Simple Curl based wrapper for Binance API for PHP scripts Feaures API support for SPOT data/trading FAPI/DAPI support for futures data/trading Curl-on

Mr Crypster 22 May 1, 2022
A PHP wrapper for Spotify's Web API.

Spotify Web API PHP This is a PHP wrapper for Spotify's Web API. It includes the following: Helper methods for all API endpoints: Information about ar

Jonathan Wilsson 796 Jan 8, 2023
Google Drive Api Wrapper by PHP

GoogleDrive Api Wrapper usage at first you need to create oauth client on google cloud platform. so go to the your google console dashboard and create

Arash Abedi 2 Mar 24, 2022
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Roman Zipp 87 Dec 7, 2022
Google Translator Api Wrapper For Php Developers.

Google Translator Api Wrapper For Php Developers.

Roldex Stark 2 Oct 12, 2022
The Official Vultr API PHP Wrapper

WIP - This is not the final API Client. Unstable release use with caution. Vultr API PHP Client. Getting Started Must have a PSR7, PSR17, and PSR18 Co

Vultr 10 Dec 20, 2022
An elegant wrapper around Google Vision API

STILL UNDER DEVELOPMENT - DO NOT USE IN PRODUCTION Requires PHP 8.0+ For feedback, please contact me. This package provides an elegant wrapper around

Ahmad Mayahi 24 Nov 20, 2022
Laravel 8.x package wrapper library for Metatrader 5 Web API

Laravel 8.x package wrapper library for Metatrader 5 Web API

Ali A. Dhillon 10 Nov 13, 2022
An unofficial wrapper client for lknpd.nalog.ru API

Unofficial MoyNalog API client An unofficial wrapper client for lknpd.nalog.ru API Install Via Composer $ composer require shoman4eg/moy-nalog Usage S

Artem Dubinin 18 Dec 14, 2022
A Gitlab API wrapper that helps to automate common actions on CI jobs

Gitlab CI client This is a Gitlab API wrapper that helps to automate common actions on CI jobs (eg: Open a merge request, Open or close an issue etc)

SparkFabrik 2 May 2, 2022
A PHP Stream wrapper for Amazon S3

S3StreamWrapper A simple stream wrapper for Amazon S3. Example <?php use S3StreamWrapper\S3StreamWrapper; S3StreamWrapper::register(); $options = a

Gijs Kunze 21 Nov 23, 2021
An asynchronous ClamAV wrapper written in PHP with amphp/socket

amphp-clamav An asynchronous ClamAV wrapper written with amphp/socket Installing composer require pato05/amphp-clamav Examples Ping and scan of a fil

Pato05 4 Feb 28, 2022
Laravel wrapper for the Facebook Graph PHP 8 SDK

Laravel Facebook Graph SDK Installation Getting started with Laravel Facebook Graph is easy - first, install the package via composer composer require

Joel Butcher 44 Dec 8, 2022
OVHcloud APIs lightweight PHP wrapper

Lightweight PHP wrapper for OVHcloud APIs - The easiest way to use OVHcloud APIs in your PHP applications - Compatible with PHP 7.4, 8.0, 8.1 - Not affiliated with OVHcloud

Germain Carré 3 Sep 10, 2022
laravel wrapper for dicom images services

laravel wrapper for dicom images services

Laravel Iran Community 4 Jan 18, 2022
A Laravel wrapper for thephpleague's Fractal package

laravel-api-response A Laravel wrapper for thephpleague's Fractal package Install Via Composer composer require lykegenes/laravel-api-response Then, a

Patrick Samson 3 Mar 15, 2021
PSR-18 compliant Circuit Breaker wrapper

Interrupt PSR-18 compliant Circuit Breaker wrapper. Acknowledgement This library is heavily inspired by: ackintosh/ganesha PrestaShop/circuit-breaker

Flávio Heleno 5 Jun 14, 2023
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023