Mailchimp API Get last campaign sent

1k Views Asked by At

Is there any direct way to get the last campaign sent on a Mailchimp account via Mailchimp API V3? So far the only way I found was to iterate over the campaigns and get the last one but it takes too much time. Thanks in advance.

2

There are 2 best solutions below

1
ekad On BEST ANSWER

I don't think you can get only the last campaign sent using only one request, but you can achieve this by making two requests to the following endpoint

/campaigns

as described here. The parameters that you need are count, status, and offset.

For the first request, set the count parameter to 1 and status parameter to sent. You will get the first campaign sent, but you will also get total_items in the response body. The total_items indicates the total number of sent campaigns in your MailChimp account regardless of the pagination and that's what you need to make the second request.

For the second request, set the count parameter to 1, status parameter to sent, and offset parameter to the value of total_items above - 1. For example if the total_items from the first request is 150, then you should set offset to 149. Setting the offset parameter to 149 will skip the first 149 sent campaigns. The campaigns field in the response of the second request will contain the last campaign sent from your MailChimp account, which is what you're looking for. This will be much quicker than enumerating through all of the sent campaigns.

1
martinnc On

This is what I did:

/campaigns?sort_field=send_time&sort_dir=DESC&status=sent&count=1

Or for anyone who needs the last campaign from a particular folder:

/campaigns?folder_id=[FOLDER ID]&sort_field=send_time&sort_dir=DESC&status=sent&count=1