How to pass an array as a parameter in url in listSubscribe() method

785 views
Skip to first unread message

Zakhar

unread,
Sep 15, 2011, 10:31:03 AM9/15/11
to MailChimp API Discuss
Hi guys,

I'm trying to use Mailchimp api. I haven't done any coding yet and
just trying to make some simple requests using Fiddler.
I know how to subscribe an email to a list, I simply send this GET
request: "http://us2.api.mailchimp.com/1.3/?
output=json&method=listSubscribe&apikey=XXXXXXXXXXXXXXX&id=XXXXXXXX&email_address=mye...@email.com&double_optin=false"
that works just fine, but at the same time leaves FNAME and LNAME
empty.
I guess I need to pass them in merge_vars parameter as an array, but I
haven't got a clue how I can do it. Besides the method documentation
doesn't even say what parameters names should be (fname? lname?).

Can anyone help with it?
thanks,
Zakhar

jesse

unread,
Sep 15, 2011, 10:37:31 AM9/15/11
to MailChimp API Discuss
Read this:

http://apidocs.mailchimp.com/gettingstarted/serialized_http_arrays.php

And then examples 2 & 3 here:

http://apidocs.mailchimp.com/api/how-to/#ex2

And your list's merge tags:

http://kb.mailchimp.com/article/where-can-i-find-my-lists-merge-tags


jesse

On Sep 15, 10:31 am, Zakhar <zakhar.zu...@gmail.com> wrote:
> Hi guys,
>
> I'm trying to use Mailchimp api. I haven't done any coding yet and
> just trying to make some simple requests using Fiddler.
> I know how to subscribe an email to a list, I simply send this GET
> request:  "http://us2.api.mailchimp.com/1.3/?
> output=json&method=listSubscribe&apikey=XXXXXXXXXXXXXXX&id=XXXXXXXX&email_address=myem...@email.com&double_optin=false"

Zakhar

unread,
Sep 15, 2011, 11:49:32 AM9/15/11
to MailChimp API Discuss
Ok, thanks jasse,
I've done it for listSubscribe without any problems, but now I have
another issue.
I'm trying to use listBatchSubscribe and the array should be different
there. I'm doing it as shown on this page:
http://apidocs.mailchimp.com/gettingstarted/serialized_http_arrays.php
sending "http://us2.api.mailchimp.com/1.3/?
output=json&method=listBatchSubscribe&apikey=XXXXXXXXXXXXXXX&id=XXXXXXXXX&double_optin=false&update_existing=true&batch[0]
[email]=ma...@email.com&batch[0][email_type]=html&batch[1]
[email]=ema...@email.com&batch[1][email_type]=html" but getting
{"add_count":0,"update_count":0,"error_count":2,"errors":[{"code":
502,"message":"Invalid Email Address: ","email":""},{"code":
502,"message":"Invalid Email Address: ","email":""}]} in response.

What am I doing wrong?
thanks,
Zakhar

jesse

unread,
Sep 15, 2011, 11:56:09 AM9/15/11
to MailChimp API Discuss
Either using invalid email addresses (like those) or not urlencoding
your values. If they are being returned blank like that, probably the
latter.


jesse

Zakhar

unread,
Sep 15, 2011, 12:14:42 PM9/15/11
to mailchimp-...@googlegroups.com
Yes, you are right, I didn't encode emails but I don't encode an email in listSubscribe() as well and it works fine.

Anyway, I tried to encode them now, basically replacing @ with %40 but it doesn't work either, returning the same response.

I read that it is more preferable to send json instead of what I'm doing now. Where can I read how to do it? I mean I know what json is, I'm interested in some examples as I've never sent json in request before.

Thanks a lot,
Zakhar

jesse

unread,
Sep 15, 2011, 1:16:46 PM9/15/11
to MailChimp API Discuss
The fact that the listSubscribe call worked without urlencoding the
values is just dumb luck. I see the problem with the
listBatchSubscribe - the parameter is "EMAIL", not "email".

If you want, you can read the JSON part of the Input Parameters
section:

http://apidocs.mailchimp.com/api/rtfm/

Then the 2nd example for listSubscribe shows doing that:

http://apidocs.mailchimp.com/api/rtfm/listsubscribe.func.php



jesse

Zakhar

unread,
Sep 16, 2011, 1:15:47 PM9/16/11
to mailchimp-...@googlegroups.com
You are right about capitals, thanks a lot for your time,

Zakhar

Reply all
Reply to author
Forward
0 new messages