MailChimp Autoresponder API stats

MailChimp’s API is great for getting/updating data about campaigns, lists, and users.  One would think that, because the API exposes so much campaign information, it would also be exposing autoresponder information, since they are just a type of campaign.

One would be sorely mistaken.

Recently, I needed to create a daily email report that would use MailChimp’s API to get the number of recipients for each autoresponder for that day.  It was going to be an easy project, up until I realized that MailChimp would let me access almost all of the information I needed – the campaigns, the segment criteria, the users – except for the information about who was going to receive the email that day.

This functionality is something that is offered on their site proper, though, so it is possible.  The “Who’ll Get This Next” link in the send settings of the autoresponder’s row on the autoresponder page will show who is going to get the email that day.  If no one fits the criteria for today, then the result set comes up empty, so “Who’ll Get This Next” should probably be called something like “Who’ll Get This Today,” but I’m not here to pick on their copy choices.

In any case, I needed to get the number of users who were going to receive an autoresponder sent out three days after they signed up for the newsletter, which meant I needed to figure out there signup date.  Because of the way the other merge vars were set up, it wasn’t clear which one of them was the signup date, or if any of them actually were.  (Read: I still have no idea.)

MailChimp’s API documentation is pretty great, and has examples for each function, but the examples don’t always cover every bit of available functionality, so it wasn’t until about the third time that I read the campaignSegmentTest function documentation that it finally clicked that the field ‘date’ they were talking about was the date a user signed up.  And, honestly, I found that whole section of the page kind of confusing at first, because the way the information was laid out didn’t make much sense to me.

But enough about my lack of reading comprehension.  For anyone else out there who is trying to figure out how to get the number of “Who’ll Get This Next” from their MailChimp autoresponder based on the signup date,  it turns out it is wicked simple.  My site is in PHP, so this is the PHP code to do it:

//This takes today's date in POSIX/Unix Time and subtracts three days from it, then converts that to a string in the format 'YYYY-MM-DD', which is the format that the date field for campaignSegmentTest requires.
$date = date('Y-m-d', strtotime('-3 days'));
//This creates a condition that the sign up date must equal the three-days-ago date just calculated
$signup_cond = array('field' => 'date', 'op' => 'eq', 'value' => $date);

This means that the full array to pass to campaignSegmentTest for a JSON call would look something like this:
array(
  'list_id' => $the_list_id,
  'options' => array(
    'match' => 'all',
    'conditions' => array(
      $condition1,
      $condition2,
      $signup_cond
    )
  )
)

It seemed pretty dang complicated the first time I had to put it all together, but now I’ve started to get the hang of it… just as the project is ending.  I hope this helped someone else figure out how to get “Who’ll Get This Next” autoresponder numbers from MailChimp!

Kick-Ass Lavender Shortbread Cookies

It’s not often that I find myself wishing that I had smell-o-vision that I could broadcast to the world — my house more often smells of animals and old-man-soup1 than it does delicious things — but right now, if you could smell my kitchen…

I have an herb share with my CSA, and the other week it included cut lavender. Obviously, my first thought was “What the hell am I supposed to make with lavender is this even edible are they secretly trying to poison me oh god it’s a conspiracy!”

Then I came back down to earth and hit up the google machine, and found this recipe on Serious Eats for lavender shortbread cookies.  Which is approximately my favoritest type of cookie in the world. (The shortbread part, not the lavender part.)  So I put out a stick of butter yesterday — because surely six ounces of butter is about half a cup! — and then immediately got distracted doing the mountain of dishes that needed doing and forgot all about it until this morning.  Thank the gods I left the butter right next to the fridge, right?  Because fridges can work by osmosis, right?

(No.)

Suffice to say, after a shower and a battle with my stand mixer, because it is heavy and I pulled every muscle in my upper body kayaking yesterday, I got to work making those cookies.  With lots of modifications because it turns out that half a cup of butter is not, in fact, six ounces (more like four) and why bother with powdered sugar when there’s honey in it anyway, and man do I even have cornstarch any more?

This, my friends, is my modified lavender shortbread cookie recipe.  They turn out just dry enough to be dipping cookies, because of the butter shortage.  The wick up just enough moisture to become soft and delicious, but not so much that they’re gross and soggy like most cookies. In fact, I would not even think about eating these without dipping them in something first, I am just saying.  I can verify that they’re delicious in hot chocolate, and have heard good things from coworkers about coffee.

I’ve not included yield because I have never found yields to be all that accurate, given how you have to obviously taste test the dough before turning it into cookies, and then taste test it again to make sure the first taste test wasn’t a fluke, and sometimes you want to make huge cookies and sometimes small cookies and and and

Kick-Ass Lavender Shortbread Cookies
Prep Time:

It took me 10 minutes to make the dough, because I was an idiot when I set the lavender to dry the other week and did not bother to take the… seeds? flowers? The lavender-y parts off the stem, so I had to do that. If you are smart, this is seriously something like a five minute recipe.

Ingredients:
  • 1/2 c (1 stick) butter
  • 1/4 c delicious honey
  • 1/4 tsp arrowroot powder/cornstarch/thickening agent2
  • 1 Tbsp lavender3
  • 3/4 tsp salt
  • 1/2 tsp baking powder
  • 2 c flour
  • water
Directions:
  1. Cream together the butter, honey, and thickening agent
  2. Add the lavender, salt, and baking powder
  3. Add the flour
  4. If it’s all flaky and not coming together in a nice ball of dough, add water until it does
  5. Put it on plastic wrap, roll it into a cylinder and roll it up in the plastic wrap
  6. Refrigerate until it’s something you can cut4
  7. Preheat your oven to 350° and line a baking sheet with parchment paper.  If you do not have parchment paper you are a sad, sad person and why are you even trying to make cookies? But I guess buttering the baking sheet would work too.
  8. Bake until done. The original recipe says 8 minutes. Mine took closer to 15, possibly because my gas oven is a thousand years old and I haven’t put a thermometer in there yet so I don’t know if the dial is accurate.
  9. Make some hot chocolate or coffee or get out a glass of milk.
  10. Dip and enjoy!
A field of purple lavender flowers.

Image by Mimova on Wikipedia.
Also can you image having to get all of the seed bits off that field by hand? D:

1 I had it at work one day, and one of my co-workers wandered into the kitchen and immediately went “Ew, what smells like old man?” Answer: Celery, an onion, and a lot of random vegetables cooked in just enough water to cover them and then puréed into a thick liquid. return

2 Let’s get some kitchen SCIENCE! all up in here! Substituting honey for sugar is wicked easy, most of the time. Take however much sugar you’re using (in this case, it was 1/2c) and divide it by four to get how much honey to use. Since 1/8c is the same as 2 Tbsp, I added the honey amounts together and added a quarter of a cup. There is your long winded explanation on how to do basic math. As for the thickening agent, commercial powdered sugar (which this recipe called for) has cornstarch in it. I have no idea why, but I’m sure it’s for a good reason. It’s a ratio of about 1 Tbsp to 1 cup, or 1:16, which is a terrifying-looking ratio when I think about trying to make it into real measurements. Since this called for 1/2c of powdered sugar, it needed 1 1/2tsp of cornstarch (or its equivalent since I don’t ever use cornstarch ever). Why then does the recipe only call for 1/4tsp? Because I am bad at math, that is why, and it came out fine anyway, so who cares stop asking questions. return

3 AKA 3tsp, for those of us who keep losing our tablespoons out of our measuring spoons no matter how many times we swear we are going to put it right back where it belongs after using it and not lose this one no really we mean it this time. return

4 I have no idea how long this actually takes beyond what the original recipe says, because I forgot I was making cookies until the next morning. Yes, this is an on-going theme in my life. return