Java Wrapper: Adding a Subscriber with Custom Fields

Dears,

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.

Thanks,
Albert

terryt terryt, 1 year 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!

Thanks!
Terry Tice


Terry Tice
Campaign Monitor

Sign up for free.
Then send campaigns for as little as $9p/m

Create an account