I want to send a broadcast email using Aweber .NET API. I can authenticate and I can retrieve a list of subscribers.
When I create a broadcast, it creates succesfully (the request doesn't fail) and I get back a JSON containing the info about the broadcast that I've just created. However, in the aweber account, I go to broadcasts and I don't see anything about the broadcast I've just created using the API! It is not sent, or scheduled or draft. It simply doesn't exist.
This is the code that I use for creating the broadcast:
string endpoint = string.Format("https://api.aweber.com/1.0/accounts/{0}/lists/{1}/broadcasts", account_id, list_id);
Request request = new Request
{
oauth_consumer_key = consumerKey,
oauth_consumer_secret = consumerSecret,
oauth_token = token,
oauth_token_secret = api.OAuthTokenSecret
};
SortedList<string, string> parameters = new SortedList<string, string>();
parameters.Add("click_tracking_enabled", "True");
parameters.Add("is_archived", "True");
parameters.Add("notify_on_send", "True");
parameters.Add("body_text", "xxxxx");
parameters.Add("subject", "yyyyyy");
request.Build(parameters, endpoint);
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/x-www-form-urlencoded";
string str = string.Empty;
str = client.UploadString(endpoint, request.Parameters);
After execution, the str string has the following content:
As you can see, the "sent" property is null, so basically it is not sent.
Thank you.
I found the solution. The broadcast needs to be scheduled. This is the code:
Broadcast broadcast = JsonConvert.DeserializeObject<Broadcast>(str);
endpoint = endpoint + string.Format("/{0}/schedule", broadcast.broadcast_id);
Request new_request = new Request()
{
oauth_consumer_key = consumerKey,
oauth_consumer_secret = consumerSecret,
oauth_token = token,
oauth_token_secret = api.OAuthTokenSecret
};
SortedList<string, string> new_parameters = new SortedList<string, string>();
new_parameters.Add("scheduled_for", DateTime.UtcNow.ToString("o"));
new_request.Build(new_parameters, endpoint);
WebClient new_client = new WebClient();
new_client.Headers["Content-type"] = "application/x-www-form-urlencoded";
str = new_client.UploadString(endpoint, new_request.Parameters);