I’m certainly no coder however use my limited PHP skills to access the Mailchimp API when I need to.
GET Mailchimp campaigns via the API
I recently needed to GET campaign information for the previous month via the Mailchimp API. Mailchimp campaign information isn’t returned sorted by date. Because I needed campaigns sent for the previous month it was important that I was sure that I was in fact getting all campaigns sent for the previous month.
To illustrate the issue I was having: Say I requested that Mailchimp return 200 campaigns via my GET request. The URL will be something like
https://us12.api.mailchimp.com/3.0/campaigns?count=200 When I viewed the results that were returned I noticed that some of the campaign data returned was for campaigns sent years ago and there were also campaigns sent very recently. I could not be sure that all campaigns sent for the previous month were in the returned data.
Query string parameters to the rescue
I searched the web as to how I could request that the data returned was sorted by date and couldn’t find a satisfactory answer. Fortunately digging in to the Mailchimp API documentation presented the solution. If you want Mailchimp to return your campaign data sorted by date then merely add sort_field=send_time&sort_dir=desc to your requesting URL (change desc to asc for ascending date). e.g.