|
|
Documentation Wiki > Developer Documentation > Web Service Guide > Technical Articles > Adding Subscribers to a List
Adding Subscribers to a ListFrom $1Table of contents(Click the banner to go to the related Docs.Code.ExactTarget.com page.) This document contains conceptual and procedural information on adding subscribers to a list via the ExactTarget web service API. You can add subscribers to an existing list using the the information in this document. Why Add Subscribers to a ListYou can use the web service API to programmatically add users to a list. How To Add Subscribers to a ListUse the sample code below as an example of how to construct your calls. Modify the call as necessary to fit the needs of your development environment or other system. When dealing with batches of subscribers, start the process with an update call and fall back to a create call as necessary, as each subscriber only needs to be created once. After being created, the subscriber will be on the All Subs list. All other list operations will be performed with an update. Setting subscriber status to Active ensures that, when they are added to the list, that subscriber will always be added in Active status (regardless of what happened in the past). Sample .NET CodeAPIObject[] objects = new APIObject[2];
for (int i = 0; i < 2; i++)
{
Subscriber sub = new Subscriber();
sub.Lists = new SubscriberList[1];
sub.Lists[0] = new SubscriberList();
sub.Lists[0].ID = 251163;
sub.Lists[0].IDSpecified = true;
sub.Lists[0].Status = SubscriberStatus.Active;
sub.Lists[0].StatusSpecified = true;
sub.Lists[0].Action = "create";
sub.EmailAddress = String.Format("customer{0}@testaccount.com",(i*2).ToString());
objects[i] = sub;
}
UpdateResult[] results = integrationFramework.Update(null, objects, out requestID, out status);
ArrayList subscribersToAdd = new ArrayList();
foreach (UpdateResult result in results)
{
Console.WriteLine(String.Format("UPDATE_____{0}_____",((Subscriber)result.Object).EmailAddress));
switch (result.ErrorCode)
{
case 12001:
Console.WriteLine("We need to add this subscriber!");
subscribersToAdd.Add(result.Object);
break;
case 13006:
Console.WriteLine("Don't worry about it. They already are on the list");
break;
}
Console.WriteLine(result.ErrorCode);
Console.WriteLine(result.StatusCode);
Console.WriteLine(result.StatusMessage);
}
objects = new APIObject[subscribersToAdd.Count];
subscribersToAdd.CopyTo(objects);
CreateResult[] createresults = integrationFramework.Create(null, objects, out requestID, out status);
foreach (CreateResult result in createresults)
{
Console.WriteLine(String.Format("CREATE_____{0}_____", ((Subscriber)result.Object).EmailAddress));
Console.WriteLine(result.ErrorCode);
Console.WriteLine(result.StatusCode);
Console.WriteLine(result.StatusMessage);
}
Console.WriteLine(results[0].StatusCode);
Console.WriteLine(results[0].StatusMessage);
This page was last updated by Ryan Williams on Fri, 06 Jan 2012 21:24:41 GMT. If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:
Tags: (Edit tags)
|
|
Powered by MindTouch 2010 |