pacely/mailchimp-api-v3

Cannot reliably make multiple calls with one instance of the wrapper

jklmnop opened this issue · 5 comments

First off, fantastic work! Thanks for writing this much needed wrapper. A+

I'm trying to use this wrapper to get a list of interest categories so then I can set them on the user update, but it looks like the wrapper retains the fields param for the second call and throws an error.

Is there a reset method or a recommended way to handle this without a second instantiation of the wrapper?

    $service = new Mailchimp\Mailchimp($api_key);

    $all_interests = $service->get("lists/$list_id/interest-categories/$interest_category_id/interests", array(
      'fields' => 'interests.id,interests.name'
    ));

    //some logic to figure out what interests for user

    $updated_user = $service->patch("lists/$list_id/members/$user_id", array(
      'merge_fields' => array(
        'FNAME' => $first_name,
        'LNAME' => $last_name
      ),
     'interests' = $user_interests

    ));

throws error

Error on line 162

Message: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Requested Fields Invalid","status":422,"detail":"Some of the fields requested were invalid: interests.id,interests.name","instance":""}

File: /vagrant/intranet/application/vendor/pacely/mailchimp-apiv3/src/Mailchimp.php

I spent the better part of a day trying like mad to get this exactly thing to work so I could execute nightly triggers that moved people to different groups in our marketing workflow. This doesn't work, so I have dumped this entire repo and implemented regular php/curl calls and now its working perfectly.

I would have preferred to use this repo but it just doesn't work for these pretty straightforward instanced.

Check out https://github.com/actuallymentor/MailChimp-API-v3.0-PHP-cURL-example/blob/master/mc-API-connector.php If you implement these calls, its not as clean but they work great 100% of the time.

Repo master, I hope you guys fix this multiple calls issue because your API is basically worthless without it. If you don't have an API that allows you to use logic to implement a workflow of calls, whats the point?

I guess that'll teach me not to read the issues before using something! @gweiss27 thanks for that link, I went on and implemented my own calls with curl, not it works flawlessly.

It seems that e.g. using a GET request after using a POST request, mixes things up. This is due to the $this->options not being cleaned before being used again. So both the 'query' and the 'json' options are still filled, which results in problems. I'll submit a PR to fix this.

aw, heck yeah! 👍

thanks for keeping the dream alive, @stefandoorn!

Hehe, ran myself into the problem @jklmnop so needed a fix :)