This custom fields thing is hanging me up.  I know how to assign values to the other parameters (,ApiKey, ListID, Email, and Name).  Those values are just strings which I can easily construct and pass to the method using the request method of campaign_monitor.rb.  However, the value of the CustomFields parameter is an array.  How do I construct this array to pass to the method?  What does it look like?  What is the format for presenting name/value pairs (name=value?))?  How are name/value paris delimited from one another?  Sorry.  Obviously I'm missing a whole lot.  Thanks for any help.

                ... doug

Ken Ken, 8 years ago

Hi Doug,

I don't know anything about Ruby, so I hope that someone who is helps us out.

Have a look at There you can see in the soap envelope what is required for the array of custom fields. I've no idea how to do that in ruby, but I hope that gets you started.
djolley, 8 years ago

Thanks, Ken, for your response.  I don't think that it is so much what Subscriber.AddWithCustomFields is expectiong; because, in theory, that is supplied by campaign_monitor.rb.  What I need to figure out is what campaign_monitor.rb is expecting from me.  I'm not sure that I'm smart enough to figure that out from the source code.  I'm hoping that someone will show up that can tell me.  I surely can't be the only one that has ever wanted to do this.  Thanks again.

         ... doug

jeremy, 8 years ago

Hi Doug,

I have updated the Ruby gem to support custom fields. You can install the gem from GitHub:

gem sources -a
gem install patientslikeme-campaign_monitor

Now when you add a subscriber to a list, you can just include a hash of custom fields:

list.add_subscriber(email, name, "City" => "Boston", "State" => "MA")

Hope that helps!

djolley, 8 years ago

> I have updated the Ruby gem to support custom fields.

That's awesome!!!

I haven't got joy here yet; but, I feel like there is light at the end of the tunnel.

With the update, I would expect that I would be able to:

require 'campaign_monitor'
cm =
cm.add_subscriber('123456789','','John Doe','Street'=>'Main Street','Country'=>'USA')

When I do that, I get a 'Wrong number of arguments (4 for 3)'.  Unfortunately, that sort of suggests to me that it's not liking the hash appended to the arguments.  I thought that perhaps curly braces '{}' should surround the entire hash and that they might have inadvertently been omitted from your post; but, including them didn't cure the problem.

WRT the 'list.add_subscriber(email, name, "City" => "Boston", "State" => "MA")' example that you provided, I couldn't get that to work either.  I know that I'm doing something stupid on that.  The problem is that I can't even get the list object created.  I'm reading the documentation to say that I can just, 'list ='123456789').  I really think that I need to do more than that; but, apparently I don't know exactly what else needs to be done.

Anyway, thanks a batch for the help.  I do hope that I'll be able to get this thing working in the near future.  Thanks again.

       ... doug

jeremy, 8 years ago

Hi Doug,

You're using a shortcut method to add a subscriber, which doesn't (yet) support custom fields. Maybe some day, but in all honesty I'd rather eliminate that method altogether so there's just _one_ way to add a subscriber.

The method on the List object should support custom fields but I see a bug. I'm working on a fix and hope to have it up on GitHub in the next few minutes.

jeremy, 8 years ago


I just pushed a fix to GitHub. Version 1.3.0 of the gem is now available.

You should be able to do something like:

list ='12345abcdef') # or find it via client.lists
list.add_subscriber(email, name, "City" => "Boston", "State" => "MA")

Note that you have to have manually added the City and State fields to your list on the CM web site.


djolley, 8 years ago

> I just pushed a fix to GitHub. Version 1.3.0 of the gem is now available.

Viola!!!  It worked great!! :)  I'm a happy camper!! :)  Thanks so much for your efforts.

> I'd rather eliminate that method altogether so there's just _one_ way to add a subscriber.

I'd be happy with it either way.  However, I think that if you are going to have multiple methods for adding subscribers, they all need to  support custom fields.  I would prefer eliminating a method over having the method retained without support for custom fields.

> Maybe some day

When that day comes, I would like to toss out a couple of things that you might consider for your next release.

First, I don't know if you saw my earlier post; but, if something could be done about the Cannot-load-rexml-security-patch warning, it would be great.  As I mentioned in the post, there is advice floating around out there to simply incorporate a hack to campaign_monitor.rb to stiffle the warning.  I'm not sure that's a good idea and in general, I don't like hacking library files (a la my comment in the following paragraph).  Regardless of how it is handled, however, it would be nice if it were handled in the package.

I might be a bit premature on my second item because I note that you indicate that the api_key may be set in the environment and that my resolve the issue.  However, I was just thinking that it would be nice to have an alternative to setting the api_key in campaign_monitor.rb.  (As I said, I'm not real fond of hacking library files.)  The thing is, in some situations (e.g., a shared server), the campaign_monitor.rb file might be shared among applications with differing api_keys.

These are just a couple of points that were on my mind.  The custom-fields fix has definitely made my day and that's enough excitement for one day.  Again, thanks so much for your help.

          ... doug

jeremy, 8 years ago

Hi Doug,

Glad that worked for you!

I agree, the other method should support the same stuff if it remains -- but I extended the library only as much as I needed (maybe a tiny bit more), and I was using the List class to add subscribers. One of these days when I have time, I'd love to clean up the interface a bit and add more documentation and code samples. Maybe even a screencast. :) The day job is keeping me pretty busy at the moment though...

I did see your earlier post about the rexml warning. I posted a reply, pointing you to the gem that patches rexml, which will fix a serious bug and secondarily make the annoying warning go away. That's really the right fix as far as I can tell.

Yes, the way the code is structured, it's hard to use multiple API keys. For example, if you use, you can't override the global constant for the API key. This is something I would like to improve at some point as time allows.

That said, if you're feeling ambitious, you're welcome to fork the project on GitHub and improve the code for the rest of us (that's all I did, forking from Jordan Brock's repo). We can pull your changes back into the PatientsLikeMe repo if it makes sense.

djolley, 8 years ago

Thanks for all the help, Jeremy.  I missed your post about the patch.  I was thinking that the 2 messages shown meant my original message and the first response.  Actually, it meant 2 responses.  Anyway, I agree, that is no doubt the way to go.  I'll get on that.

As far as my forking the project goes, you flatter me, but I think that is a bit beyond my capabilities.  You did give me an ego boost by mentioning it though. :)

Have a great day and thanks again.

          ... doug

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free