TransWikia.com

Mailchimp API limit in post request

Stack Overflow Asked on November 27, 2021

I am working with the mailchimp api. I am running into a problem where i exceed their limit of 10.
In the get request you can solve this with pagination and offset. But how can you solve this in a post request, it’s not like you can have pagination in post requests..

This is how my code is running :

allEmails.forEach(email => {
    const emailHash = md5(email); 
    if(mailChimpMails.indexOf(email) === -1) {
        mailChimpPost('POST',`lists/4d2d65c130/members` , JSON.stringify({"email_address" : email , "status": "subscribed"})).then( res => {
            console.log(res);
        }).catch(err => {
            console.log(err); 
        });
    }else{
         mailChimpPost('PATCH',`lists/4d2d65c130/members/${emailHash}` ,  JSON.stringify({"status": "subscribed"})).then(res => {
             console.log(res)
         }).catch(err => {
             console.log(err); 
         });
    }
})

All emails is an array of emails which i loop through and add them individually to my audience in mailchimp. It adds a few but after a while of running it throws an error of 429 :

statusCodeError: 429 –
"{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Too
Many Requests","status":429,"detail":"You have exceeded the
limit of 10 simultaneous
connections.","instance":"myinstance"}"

One Answer

Maybe a little late, but better late than never and maybe you've discovered this in the meantime, yourself.

Use the batch endpoint

https://mailchimp.com/developer/marketing/api/lists/batch-subscribe-or-unsubscribe

Here's an example of CURL code that should get you on your way:

curl -X POST 
  'https://${dc}.api.mailchimp.com/3.0/lists/{list_id}?skip_merge_validation=<SOME_BOOLEAN_VALUE>&skip_duplicate_check=<SOME_BOOLEAN_VALUE>' 
  --user "anystring:${apikey}"' 
  -d '{"members":[],"update_existing":false}'

Where members is an array of objects, with at least one property email_address.

The batch job is passed off to Mailchimp relatively quickly freeing up both your app and your connections to MailChimp.

Answered by reblevins on November 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP