[SOLVED] ListSubscribe returns 'true' but list is still epmty.

Sep 2, 2011 at 12:38 PM
Edited Sep 2, 2011 at 12:45 PM

Here is my code:

 

public sealed class MailingService : IMailingService
{
	private readonly string _apiKey;
	private readonly string _listId;

	public MailingService(string apiKey, string listId)
	{
		_apiKey = apiKey;
		_listId = listId;
	}

	public bool Subscribe(string email, string name)
	{
		var mc = new MCApi(_apiKey, true);

		var subscribeOptions =
			new Opt<List.SubscribeOptions>(
				new List.SubscribeOptions
					{
						SendWelcome = true,
						UpdateExisting = true,
					});

		var merges =
			new Opt<List.Merges>(
				new List.Merges
					{
						{"NAME", name}
					});

		return mc.ListSubscribe(_listId, email, merges, subscribeOptions);
	}
}

Method Subscribe returns 'true' and in MailChamp dashboard I can see my calls, but target list is still empty. 
BTW, same task implemented using PerceptiveMCAPI does the work, but its API is ugly.
What I'm doing wrong?
Sep 2, 2011 at 1:18 PM
Edited Sep 2, 2011 at 1:21 PM

I'v figured out where I was wrong. Though there may be a minor bug. Here working code:

public bool Subscribe(string email, string name)
{
	var mc = new MCApi(_apiKey, true);

	var subscribeOptions =
		new Opt<List.SubscribeOptions>(
			new List.SubscribeOptions
				{
					DoubleOptIn = false,
					SendWelcome = true,
					UpdateExisting = true,
				});

	var merges =
		new Opt<List.Merges>(
			new List.Merges
				{
					{"NAME", name}
				});

	return mc.ListSubscribe(_listId, email, merges, subscribeOptions);
}

So, problem was in missing DoubleOptIn parameter. It can be either true or false, but it is required.

Coordinator
Sep 2, 2011 at 1:53 PM
Edited Sep 3, 2011 at 7:53 PM
Hi,

1. According to their docsdouble_opt_in is optional.

When double_opt_in is set to true (default value if omitted), MailChimp sends a Subscription confirmation email to a new contact. 
This contacts will not be visible as subscribers in your list until after s/he confirmed the subscription
If subscription is never confirmed or if the subscription request email is caught by spam filters, your contacts will never become a member of your list.

2. Opt<'T> type has implicit conversion operator. So u can simplify your code:

public bool Subscribe(string email, string name)
{
	var mc = new MCApi(_apiKey, true);

	var subscribeOptions =
		new List.SubscribeOptions
			{
				DoubleOptIn = false,
				SendWelcome = true,
				UpdateExisting = true,
			};

	var merges =
		new List.Merges
			{
				{"NAME", name}
			};

	return mc.ListSubscribe(_listId, email, merges, subscribeOptions);
}


Sep 23, 2011 at 1:14 PM

I'm pretty sure that I have tried all three options. When I omit DoubleOptIn, the opt-in letter doesn't comes and the subscriber doesn't appears in the list. When DoubleOptIn is present, all goes as it said in docs.