Coder Social home page Coder Social logo

mailchimp-api's People

Contributors

adamholte avatar alamantus avatar bkuhl avatar drewm avatar ejeliot avatar freekmurze avatar gondo avatar insti avatar kierate avatar leanne616 avatar lornajane avatar lracicot avatar marvinschroeder avatar maxhelias avatar mrailton avatar pdbreen avatar pixney-william avatar ricardo-vargas avatar rolandsaven avatar rolice avatar slaffik avatar slavielle avatar spisakni avatar theirritainer avatar tobya avatar vatps avatar vincentlanglet avatar vojtasvoboda avatar wesbos avatar wlcx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailchimp-api's Issues

Users subscribe

I can't add an user to a list, I don't get any error message.

  public function addUserToList ($email, $name, $last_name, $list_id){
    $mc       = $this->getMailService ();

    // List data.
    $data     = array (
      "id"                => $list_id,
      "email"             => array ("email" => $email),
      "merge_vars"        => array ("FNAME" => $name, "LNAME" => $last_name),
      "status"            => "subscribed",
      "double_optin"      => false,
      "update_existing"   => true,
      "replace_interests" => false,
      "send_welcome"      => false
    );

    // Insert user into list.
    $result   = $mc->call ("lists/subscribe", $data);

    // Send HTTP response with all data.
    var_dump ($result);
  }

  public function listAction(){
    //$this->getCampaigns();
    //$this->getList();

    $this->addUserToList("[email protected]", "John", "Dole", "29d1ca9e97");
  }

I get this response from your api.

array (size=3)
  'email' => string '[email protected]' (length=19)
  'euid' => string '8757dd3098' (length=10)
  'leid' => string '93045953' (length=8)

I check the list using mailchimp panel, and list is empty.

the curl option seemed to not have worked for me

in the background curl is used

require("vendor/autoload.php");
$lukas_api_key = 'c73ec7be5f2edf512565f08d70346742-us12';
$lukas_list_id = '1f246b6cec';
$email = "[email protected]";


$MailChimp = new \Drewm\MailChimp($lukas_api_key);
$isValid = $MailChimp->validateApiKey();
$result = $MailChimp->call('lists/subscribe', array(
  'id'                => '' . $lukas_list_id . '',
  'email'             => array('email'=>'[email protected]'),
  'merge_vars'        => array('FNAME'=>'Somefirst', 'LNAME'=>'Somelast'),
  'double_optin'      => false,
  'update_existing'   => true,
  'replace_interests' => false,
  'send_welcome'      => false,
));
print_r($result);

result is null and nothing got added to my list

POST call returns encoded result

Hi,

When using the api V3 branch, I had no errors while using GET to retrieve lists.
But when creating a list, the class returns null. Looking into the code shows me that at this line :
$result = curl_exec($ch);

$results contains :
"���<��n� �_�b�%�n蔹�Ե�v�@�I,�@�D�N��urUG��|��ad/h�����ڀ��\������ZK��jC�m�$N('��ٹQ@�Xk��9ffWwk:#$��~��E ���[���+����n�����i�{A��%�6�$��|n1@��#�r:��#W��c�rAO�yx���F�Q������Z���jJ�<�CLO�� ��9Q:݈i�H�k��>g>��N����/P)��('�<����X�H��������z��y�����l���f�"

I don"t know if it is specific to my case or my server, but I prefer to let you know.
I could fix this by adding this line :
curl_setopt($ch, CURLOPT_ENCODING, '');

after :
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

Maybe it will help someone else.

Regards.

File_get_content 500 error

Hi,

When there's an error in the API call and you use file_get_content to retrieve data, the 500 http error prevent it to actually retrieve the response explaining the error.
Fix :
add 'ignore_errors' => true to stream context.

Fatal Error: Class Not Found

Hello, tried the code on localhost and it's working fine. But when deployed to test server, I get error PHP Fatal error: Class 'Drewm\Mailchimp'

What am I doing wrong?
I used composer to install...
and the site is based on wordpress
therefore I call require_once( ABSPATH . "vendor/autoload.php" )

help...

It's not possible to UNsubscribe

It works perfect for subscribe, but if I try to change the code in:

require_once 'MailChimp.class.php';
$result = $MailChimp->call('lists/unsubscribe', array(
'id' => 'xxx',
'email' => array('email'=>'xxx'),
'delete_member' => false,
'send_goodbye' => false,
'send_notify' => false,
));
print_r($result);

it shows the error: Fatal error: Call to a member function call() on a non-object in /web/htdocs/www.xxx.com on line xx

Am I doing something wrong?

Please help me!

Tag release?

Hello Drew,

Thank you for this fantastic wrapper! It definitely makes MailChimp API calls a breeze!

I am not sure how happy you are with the repository and whether you are going to make any further changes in the near future, but could you possibly create a tag for the repository so there may be a stable version to refer to in Composer?

dev-master is the only option at the moment.

Thank you in advance!

Best regards,

Edmund

Not sending opt-in mail?

Heya,

Splendid wrapper, thanks alot for putting it out there!
I do have some trouble getting it to send out opt-in, it just adds the email to the list..

$MailChimp = new MailChimp('xxx-xxx');
$result = $MailChimp->post('lists/xxx/members', array(
    'email_address'     => $email,
    'status'            => 'subscribed',
    'merge_fields'      => array('FNAME'=>$fname, 'LNAME'=>$lname),
    'double_optin'      => true,
    'update_existing'   => false,
    'replace_interests' => false,
    'send_welcome'      => true,
));

Does it recognize my IP or something maybe? Any clue?

[minor issue] Double slash in API URL.

There is a double slash in the URL the API client calls.

See line 21:

private $api_endpoint = 'https://<dc>.api.mailchimp.com/2.0/';

which has an end slash and line 64

$url = $this->api_endpoint.'/'.$method.'.json';

which adds a slash in between, the API seems to work just fine, this just isn't that neat.

Documentation issue

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

include('./Mailchimp.php');

It should be a capital C in MailChimp

Why Composer?

Why is the install process stating to use Composer? Composer installs tonnes of other unnecessary files, and all to avoid this line:

include('MailChimp.php');

You also state use it to install dependencies. What dependencies are there for this file, I cant see any.

It looks to me as if we can just upload the file and use this include line, then we can instantiate a new MailChimp class right away.

Composer is over the top for this - unless your app uses composer, then fine, but you should include "normal" instructions. Many users don't use composer, so you are just overcomplicating a simple task.

My two cents!

Don't decode the json

Better to let the user decode the result themselves or at least provide a parameter. If you want to use this with an ajax call you'll probable end up having re-encoding it.

Return Blank...

I am not even able to get lists using the example shown on the doc. I wrap the instantiation inside a class.

download dist

I've set composer to prefer "dist". But I get an error:

Failed to download drewm/mailchimp-api from dist: You must enable the openssl extension to download tiles via http...

I really need the dist version.

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!

the requested package drewn/mailchimp-api could not be found in any version

i tried to install drewn/mailchimp-api with this strings
{
"require": {
"drewm/mailchimp-api": "*"
}
}
and i get this error; Problem 1
- The requested package drewm/mailchimp-api could not be found in any versio
n, there may be a typo in the package name.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common
problems.

euid and leid

Is there a way to add the euid or leid I get an error with every api call ?

thanks

API Key not found

Suddenly I keep receiving the following error. It was working before, but suddenly has stopped, even though I have changed nothing. I wonder if the key is not being being sent across probably. The problem happens on two different sites (on different servers).

detail: "Your request did not include an API key."
instance: ""
status: 401
title: "API Key Missing"
type: "http://kb.mailchimp.com/api/error-docs/401-api-key-missing"

function makeRequest as protected

Hi, this is nice simple wrapper, thanks!

I want to proccess errors from Mailchimp API as Exceptions. So I created my MailChimp class:

namespace Codemate;

class MailChimp extends \Drewm\MailChimp
{
    public function call($method, $args=array())
    {
        $response = $this->makeRequest($method, $args);

        if (isset($response['status']) && $response['status'] == 'error') {
            throw new MailChimpException($response['name'].': '.$response['error']);
        }

        return $response;
    }
}

class MailChimpException extends \Exception {}

And than I can use it in my project like this:

try {
    $mc = new \Codemate\MailChimp($this->context->parameters['mailchimp']['apiKey']);
    $mc->call('lists/subscribe', array(
        'id'                => $this->context->parameters['mailchimp']['listId'],
        'email'             => array('email' => $data['email']),
        'update_existing'   => true
    ));
} catch (\Codemate\MailChimpException $e) {
    if ($e->getMessage()) {
        \Nette\Diagnostics\Debugger::log('mailchimp list subscribe error: '.$e->getMessage(), self::ERROR);
        $this->flashMessage($e->getMessage(), 'error');
    } else {
        throw $e;
    }
}

Problem is, that your function makeRequest is private, so I cannot overide it, check $response and throw Exceptions in my MailChimp class.
Can you change this function to protected?

Or if you'r interested in throwing Exceptions instead of only returning $response, I can send pull-request with this improvement.

Thanks for the replay!

cURL fails on Windows servers

Hi,

Just a quick note to help anyone else with this issue.

cURL request fails and just returns false on Windows servers when $verify_ssl = true. Change to false to fix.

Had to add code to output cURL error message to work out what the problem was.

Other than that, working nicely with API V3 - thanks.

Update Bach

Hi!
How to update/insert in bacth process? and merge fields
Thanks

Error Handling

Currently, a failed request returns false without any indication as to what the error is. It would be nice if a curl error was returned in this event:

if (!$result) {
echo 'error: '.curl_error($ch);
}

Can this send emails?

Can this wrapper send emails at all? It works great for adding and updating members, thanks!

Is there a way to test API key ?

I'd like to test the mailchimp api key, to test if the user enter the right one, for example if my api key var is wrong
i have a php notice :
notice: Undefined offset: 1 in /MailChimp.php on line 31
If someone have an idea, maybe be ping the mailchimp API

Thanks

campaigns/list folder_id issue

I can't get any version of this to work. Essentially, I want to list all campaigns in a specific folder. (Doesn't work with single quotes around the 749 either.

$MailChimp->call('campaigns/list', array(
'folder_id' => array('folder_id' => 749)
)
);

$MailChimp->call('campaigns/list', array('folder_id' => 749));

Added patch support to wrapper

Thanks so much for writing this, it has saved me a lot of time. One quick addition - I was having trouble getting my email addresses to update, so added the following to line 100 below case 'delete':

case 'patch':
                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); 
                    break;

Thanks!

API v3 - looks like "PUT" request is not handled (required for updating)

in MailChimp.php line 82 - no case for "put"

 switch($http_verb) {
            case 'post':
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); 
                break;

            case 'get':
                $query = http_build_query($args);
                curl_setopt($ch, CURLOPT_URL, $url.'?'.$query);
                break;

            case 'delete':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;

            case 'patch':
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
                curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); 
                break;
        }

Passing through PROXY

I'm using this class and in my office and we have to connect CURL through a proxy, I added a method to set up a proxy. It might be useful for somebody else.

New subscription -> Group (Interests, Sex)

Hello,

In my ML I have two groups Interests-> Cars, Bikes, Boats and Sex-> Male,Female

How do I make a call to subscribe to 1or more interests ?? and only 1 Sex.

Sample:

$result = $MailChimp->post('lists/'.$listID.'/members', array(
'email_address' => $email,
'status' => 'pending',
'merge_fields' => array(
'USERID' => $user_id,
'FNAME'=> $first,
'LNAME'=> $last,
'EMAIL' => $email,
'BDAY' => $bday,
'SEX' => $sex
), // merge_fields array end
'interests' => array( 'Cars' => true, 'Bikes' => true, 'Boats' => false ), // interests is name of group
'sex' => array('male' => true, 'female' => false) // sex is name of group
));

SSL3 issue + param issue

Having a couple of issues.

  1. missing second param
    from your sample code:
    $MailChimp = new \Drewm\MailChimp('abc123abc123abc123abc123abc123-us1');
    print_r($MailChimp->call('lists/list'));

returns an error for missing second argument. It looks like the call method is expecting a "params" value.

something like print_r( $MailChimp->call( 'lists/list', array( 'nothing' => true ) ) ); of course fixes that issue.

  1. again with your basic code example, i'm getting an SSL error from mailchimp:
    Mailchimp_HttpError: API call to lists/list failed: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Applications/MAMP/htdocs/betterbloodsugar/wp-content/plugins/bbs-mailchimp/src/Mailchimp.php on line 225

It is not until i add curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); into the call method that things seem to work.

It appears that since curl 7.10 this settings is default of True. I'm using curl 7.20.0, thus this explicitly needs to be turned off now. I wonder if prior to 7.10 the default was false.

Using with php 5.2.17 - Can I? How? Server set.

Hi! I have a need to use a simple php mailchimp wrapper quick for subscribing users to lists and sending an intro campaign. Depending on the data entered.

My server is set at php 5.2.17 and can't change it for the moment.

Can I use this? It's basically the best last stable still used by a lot, before moving to 5.3+ for most servers.

Are there php 5.3 dependencies I can change? Or should I try it as is?

Thanks very much for any information, help, light you can shed on this. Can't make them move quite yet.

Best,

-C

API v3 composer

Is there a way to install the MC v3 API through composer ?
Currently I'm only able to install the old one...

thanks !

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.

Readme example yields blank page with no error

Hi, I've installed this as per the instructions in the readme but the example code given to retrieve all lists yields a blank page - no output at all. I'm running php5.5 on windows - any ideas where to start? Thanks

Signup Source

Is there a way to pass the signup source so that it doesn't appear as "API - Generic". I'm trying to create a segment based on where the user signs up.

Class not found

Hi, I'm using a local WAMP server, php 5.3. I enabled curl even though it said not necessary.
I did not use Composer, just include MailChimp.php, and I get this error:

Fatal error: Class 'MailChimp' not found in ...

I do an echo in the file to make sure it's being included and it is. If I comment out the namespace line I don't get the error anymore but nothing happens either. I mean my form contact form gets posted, does other backend stuff like add form details to my db but that's it.
I'm using the add subscriber example.
help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.