PDA

View Full Version : A MailChimp API offering



danwalsh46
21-Nov-2017, 12:43 PM
The attached basic Windows program shows you how to add a Member to a MailChimp List. To use it you need the following:

1) A MailChimp account with at least one List. https://mailchimp.com/

2) An API key. In your Account under Extras, you will find info on creating an API key.

3) The ID number of your List. http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/ The getting started doc is relatively short and easy to follow. After reading it, I used the playground to GET my List. The ID is in the JSON that's returned.

To create a new Member in your list, you need an MD5 hash of the lowercase value of the member's email address. Searching the forum, I found code contributed by Clive Richmond.

The code uses Basic Authorization, not oAuth. Read about it here: https://en.wikipedia.org/wiki/Basic_access_authentication The Base64EncodeString function in my code was in the DAW doc.

Hopefully this will jump-start your use of this API.

ps: the List ID & API Key in the code are bogus, you will need your own to run the program successfully.

Mike Cooper
21-Nov-2017, 02:28 PM
Thanks Dan

Peter van Mil
21-Nov-2017, 04:17 PM
Thanks. I will give it a try.

Garret Mott
21-Nov-2017, 05:55 PM
I see a DISD talk in your future sir! Early March, in fact... :)

Mark Powers
22-Nov-2017, 10:19 AM
I agree with Mr. Mott - DISD presentation Daniel?
Mark

danwalsh46
23-Nov-2017, 07:34 AM
Sure

Nicholas Herlick
30-Jun-2019, 03:16 PM
Dan, I am working with your MailChimpTest.src, adapting it for my test Playground. I get an Error 404, Resource Not Found, Invalid Path.

Can I email you the code privately (need email) - and can you see anything that's wrong? I didn't see a reference to the ListID they say must be specified. I plugged one in as part of sFilePath, but maybe it's the wrong place. My email is: nick@memsys.com

Focus
1-Jul-2019, 05:04 AM
In Dan's original example he has just hard coded it into the URL

Move "3.0/lists/04d61f6586/members/" to sFilePath

Nicholas Herlick
1-Jul-2019, 10:55 AM
In Dan's original example he has just hard coded it into the URL

Move "3.0/lists/04d61f6586/members/" to sFilePath

What I changed is...

Move "us15.api.mailchimp.com" to sHost // his starts "us14" but my playground is on "us15"

// then I changed sFilePath as per what's needed (I think). They seem to refer to ListID as "AudienceID"
//Move "3.0/lists/04d*61f586/members/" to sFilePath
Move "3.0/lists/5266bc0674/WXYZ donors" to sFilePath

But it still returns a 404.

Focus
1-Jul-2019, 11:01 AM
I'm not quite sure why you have put "WXYZ donors" on the end of the path as this is not an end point and if it were it has not been encoded

His example is adding a member to an existing list

So if you want to do the same just change the list id for your own and the host as you have done

Focus
1-Jul-2019, 11:06 AM
Oh I see now he is doing a PUT so that is to update and exiting member or add a new one

So you will see the code creates an MD5 hash of the email address and adds this to the URL before making the call

https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#edit-put_lists_list_id_members_subscriber_hash

Nicholas Herlick
1-Jul-2019, 02:18 PM
Oh I see now he is doing a PUT so that is to update and exiting member or add a new one

So you will see the code creates an MD5 hash of the email address and adds this to the URL before making the call

https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#edit-put_lists_list_id_members_subscriber_hash

OK I mistook "members" for his list name. So I changed my string to my list name. When I changed it to "members" it worked. Thanks!

Nicholas Herlick
2-Jul-2019, 11:28 AM
I got our flavor of MailChimpTest.src to work using a new playground. Thanks to all for tips/tricks to make it work. We're going to do what I think will be a robust API, and I'll share code samples from it when things are working. ~Nick