Wednesday, 15 July 2015

wordpress - Mailchimp Batch Subscribe 2.0 Returns False on 500+ records (PHP) -


I have a PHP script to update Mailchimp using the batch-subscribe from my WordPress userlist. ()

When I send about 400 records, everything works fine. All records have been added, and I get a return from the number of extra records from the API, etc.

If I have around 600 or more (I have 730 customers), then all records are added to the scam, but the API returns false, I check it again with false ===, and it's wrong is. I did not get any error - it just returns false (but all records are added to the mailchap).

Mailchimp says "Max batch size varies depending on the amount of data in each record, although you have 5k-10k records based on your experience."

I'm not close to that, and every record is being added to the mailchip list just fine. I did not get a refund from the API.

I increased my timeout value to 5 minutes. I also switched to using different records, suspecting that I might have a record with something that is messing it up, but there was a similar behavior with its various records.

I'm using the DrewM library interface with Mailchimp API version 2.0 I'm sure that the DrewM is using the post for the request, and it does. ()

Any thoughts that are happening due to this?

Here is the code:

  function mailchip dialupdate () {set_time_limit (300); $ Api = get_mc_api (); $ McListId = get_mc_mailing_list (); $ MailChimp = New \ Drewm \ MailChimp ($ api);  

...

  foreach ($ $ bloggers as a user) {$ userinfo = get_userdata ($ user-> ID); $ Location = ... // code to obtain the location $ merge_vars = array ('FNAME' => $ userinfo- & gt; first_name, 'name' = & gt; $ userinfo- & gt; last_name, 'MMERGE3' => $ userinfo- & gt; user_login, // username 'MMERGE6' => $ location // location); $ Batch [] = array ('email' = & gt; array ('email' = & gt; $ user- & gt; user_mail), 'merge_wars' = & gt; $ merge_vars); } // and forehack // mailchap calls $ reval = $ MailChimp- & gt; Call ('lists / batch-subscribed', array ('id' => $ MCLIIID, // your mailchip list id 'batch' => $ batch, 'update_existing' => true)); If ($ retval === false) {resonant "mailcip API returned"; } Echo: 'Added:' $ ['add_count'] "
"; Resonance 'updated:' $ retal ['update_count'] "
"; Echo 'Errors:' $ Retal ['error_count'] "
"; }

With support from Mailchimp support, I can trace the problem and solve it Was able to.

The issue was actually in the Dru M envelope. The content-length section of the header was apparently not working correctly on long calls. I removed it, and everything started working fine.

The basic section of the DrewM code (not working):

  $ result = file_get_contents ($ url, null, stream_context_create (array ('http' = & gt; ; Array ('protocol_version' => 1.1, 'user_agent' => 'PHP-MCAPI / 2.0', 'method' = & gt; 'POST', 'header' = & gt; "content-" content \ R \ n "." Strlen ($ json_data). "\ R \ n", 'content' = & gt; $ json_data,),)));  

Update section of code (function):

  $ result = file_get_contents ($ url, null, stream_context_create (array ('http' = & gt; Array ('protocol_version' => 1.1, 'user_agent' = & gt; 'PHP-MCAPI / 2.0', 'method' = & gt; 'POST', 'header' => "content-type: app / Jason \ r \ N "." Connection: Closed \ r \ n ", 'Content' = & gt; $ json_data,),)));  

No comments:

Post a Comment