Java Wrapper: Adding a Subscriber with Custom Fields


I am trying to add a sbscriber to an existing list which has custom fields. I understand that only by doing this should work:

subscriber.CustomFields[0].Value=The value;

It runs correctly but then when I check in Campaign, the subscriber has been added but the custom field is empty. This is the full code sequence

Lists listAPI = new Lists(listID, new JerseyClientImpl(clientAPIKey));
Subscribers subscriberAPI = new Subscribers(listAPI.getListID(),new JerseyClientImpl(clientAPIKey));
SubscriberToAdd subscriber = new SubscriberToAdd();
subscriber.CustomFields = new CustomField[] { new CustomField()};
subscriber.ListID = listAPI.getListID();
subscriber.State = "Active";
subscriber.Resubscribe = true;
subscriber.EmailAddress = email;
subscriber.Name = name;
subscriber.CustomFields[0].Value=The value;

Is there something I am missing? appreciate your help.


terryt terryt, 4 years ago

Hi Albert,

Thanks for getting in touch!

The only thing I can see that would be missing is the key for the custom field.  So, you would need something like this:

subscriber.CustomFields[0].Key=The field name/personalization tag;
subscriber.CustomFields[0].Value=The value;

Hope that helps.  Feel free to get in touch if you need anything more!

Terry Tice

Terry Tice
Campaign Monitor

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