1

I am using MailChimp API 3.0. I am trying to get email lists from the new API and the following works fine.

http://usXX.api.mailchimp.com/3.0/lists/3399JU772?apikey=XXYY3399DDFF87336663-usXX

The API Key and list Id I provided are just fake. But using the above code gets me the list id and related contents. However, I tried to grab just only name of the list using the following code

http://usXX.api.mailchimp.com/3.0/lists?fields=lists.name/99uy6633?apikey=xxxyyyzzzxxxeeee-usXX

and I get the following error

   {"type":"http://kb.mailchimp.com/api/error-docs/401-api-key-missing","title":"API Key Missing","status":401,"detail":"Your request did not include an API key.","instance":"99hhytt-5444f-453gfgfg-bfgfg4bd-4545ggfg"}

Is there a syntax error? I couldn't find syntax in the documentation except here

I appreciate your help.

WowBow
  • 7,137
  • 17
  • 65
  • 103
  • you have two `?` symbols in your query, replace the second one with `&` and try again. also `lists.name/99uy6633` does not seem valid - you might need to url-encode `/` – Roman Vottner Jul 16 '15 at 21:15
  • Yeah, that second URL is just no good. `/3.0/lists/{list_id}/?fields=lists.name`. and also, when you start using the API for real, it's advisable to not put the API key in the querystring. – TooMuchPete Jul 16 '15 at 21:21
  • {"type":"http://kb.mailchimp.com/api/error-docs/422-requested-fields-invalid","title":"Requested Fields Invalid","status":422,"detail":"Some of the fields requested were invalid: lists.name","instance":"93sdfsdfa-fdd2-4344f-3434-fdfd3434"} – WowBow Jul 16 '15 at 21:29
  • @TooMUchPete No Luck but a different message this time and I know the field names are correct. – WowBow Jul 16 '15 at 21:30
  • 1
    Without seeing your actual request it's tough to see what's going on, but it really sounds like you just need to read the docs another time and do a bit more debugging. Don't add the `fields` parameter until the rest of the request works, etc. – TooMuchPete Jul 16 '15 at 21:35
  • True that. I am going over the docs and its a not complete yet, I guess. Thank you though. – WowBow Jul 16 '15 at 21:55

1 Answers1

2

MailChimp API 3.0 has currently an issue if multiple query-parameters are provided (at least apikey and exclude_fields or fields). Instead of providing the apikey as query-parameter you can provide it within the password field of the authorization header. The username can according to the documentation be anything you want.

A request for a partial response of name and the city of the contact of a list with a username of abcd and an apikey of XXYY3399DDFF87336663-usXX has to look like this if invoked with curl:

curl -XGET -H "Authorization: Basic YWJjZDpYWFlZMzM5OURERkY4NzMzNjY2My11c1hY" https://usXX.api.mailchimp.com/3.0/lists/{listId}/?fields=name,contact.city

Note that the username and password are a base64 encoded representation of abcd:XXYY3399DDFF87336663-usXX!

The response for the request from above is as follows in my case:

{ "name": "testList", "contact": { "city": "Vienna" }}
Roman Vottner
  • 12,213
  • 5
  • 46
  • 63
  • Thank you for your explanation. That explains it. That means we can't test this using just URL on the browser. Right? Btw, I don't use curl but Java for now. – WowBow Jul 17 '15 at 18:00
  • Why should this prevent you if you use Java? Even if you use `URL` and `HttpUrlConnection` you [can set HTTP headers](http://stackoverflow.com/questions/12732422/adding-header-for-httpurlconnection). Java 8 now also ships with a Base64 class officially (pre Java 8 you could use implementation from other Vendors or an internal one from Sun/Oracle). Moreover, this issue of MailChimp not being able to handle apikey + fields as query parameters within the same request may also be only a temporal thing – Roman Vottner Jul 17 '15 at 18:45
  • I didn't mean I can't use it in Java but I was leaving that note as FYI. I use Java 7 for now. I'll give it a try. Thank you. – WowBow Jul 17 '15 at 20:34
  • Btw, do the new API has a webhook where we can register our application to hear changes on their side (when users subscribe/unsubscribe) ? How about batch processing of subscription? The new documentation looks a bit lose and I wasn't able to get all the info at once. Thank you! – WowBow Jul 17 '15 at 22:18