Joe Birkin Joe Birkin - 9 months ago 54
PHP Question

Empty MailChimp list members API response - works on API playground

Having a bit of a weird issue with a script that's previously been running for a couple of months that searches a MailChimp list for users that are subscribed but whose accounts haven't been updated in over 2 weeks (we're running nightly updates/sync on a mailing list from a database).

It was working absolutely fine up until about a week ago when I made a couple of changes. I went back and tried to put it how it was but am still getting an empty response for the query. This is the query:

/3.0/lists/{list}/members?status=subscribed&before_last_changed={-2 weeks}

I know for a fact there are around 15,000 addresses that match those query parameters, and have verified the parameters using the API playground. Searching using either the status or before_last_changed parameter works fine and returns results as expected. I've also tried changing the parameters. I also used to have
in the parameters but it doesn't work with or without this (or a lower number).

I'm using the PHP MailChimp available on Github here.

Does anyone have any advice on how to troubleshoot or resolve this issue?

Edit: I'm using
gmdate('c',strtotime("-2 weeks"))
for the date.

Answer Source

It turned out to be an issue with cURL timing out. The error handling is pretty poor in that API and the timeout is set at 10 seconds. As the list is quite large and the query is quite granular, it was taking longer than 10 seconds to process.