public PatchReturnStatus AddColumnToDataExtension(string customerKey, string addFieldName, DataExtensionFieldType fieldType) { ET_DataExtension patchDataExtension = new ET_DataExtension(); patchDataExtension.AuthStub = _etClient; patchDataExtension.CustomerKey = customerKey; ET_DataExtensionColumn addedField = new ET_DataExtensionColumn() { Name = addFieldName, FieldType = fieldType }; patchDataExtension.Columns = new ET_DataExtensionColumn[] { addedField }; PatchReturn patchFR = patchDataExtension.Patch(); PatchReturnStatus status = new PatchReturnStatus() { Status = patchFR.Status.ToString(), Message = patchFR.Message.ToString(), Code = patchFR.Code.ToString(), ResultsLength = patchFR.Results.Length }; return(status); }
static void TestET_ListSubscriber() { var newListName = "CSharpSDKListSubscriber"; var subscriberTestEmail = "*****@*****.**"; Console.WriteLine("--- Testing ListSubscriber ---"); var myclient = new ET_Client(); Console.WriteLine("\n Create List"); var postList = new ET_List { AuthStub = myclient, ListName = newListName, }; var prList = postList.Post(); if (prList.Status && prList.Results.Length > 0) { var newListID = prList.Results[0].Object.ID; Console.WriteLine("\n Create Subscriber on List"); var postSub = new ET_Subscriber { Lists = new[] { new ET_SubscriberList { ID = newListID } }, AuthStub = myclient, EmailAddress = subscriberTestEmail, Attributes = new[] { new ET_ProfileAttribute { Name = "First Name", Value = "ExactTarget Example" } }, }; var postResponse = postSub.Post(); Console.WriteLine("Post Status: " + postResponse.Status.ToString()); Console.WriteLine("Message: " + postResponse.Message); Console.WriteLine("Code: " + postResponse.Code.ToString()); Console.WriteLine("Results Length: " + postResponse.Results.Length); if (!postResponse.Status) { if (postResponse.Results.Length > 0 && postResponse.Results[0].ErrorCode == 12014) { // If the subscriber already exists in the account then we need to do an update. // Update Subscriber On List Console.WriteLine("\n Update Subscriber to add to List"); PatchReturn patchResponse = postSub.Patch(); Console.WriteLine("Post Status: " + patchResponse.Status.ToString()); Console.WriteLine("Message: " + patchResponse.Message); Console.WriteLine("Code: " + patchResponse.Code.ToString()); Console.WriteLine("Results Length: " + patchResponse.Results.Length); } } Console.WriteLine("\n Retrieve all Subscribers on the List"); var getListSub = new ET_List_Subscriber { AuthStub = myclient, Props = new[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" }, SearchFilter = new SimpleFilterPart { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new[] { newListID.ToString() } }, }; var getResponse = getListSub.Get(); Console.WriteLine("Get Status: " + getResponse.Status.ToString()); Console.WriteLine("Message: " + getResponse.Message); Console.WriteLine("Code: " + getResponse.Code.ToString()); Console.WriteLine("Results Length: " + getResponse.Results.Length); foreach (ET_List_Subscriber resultListSub in getResponse.Results) { Console.WriteLine("--ListID: " + resultListSub.ID + ", SubscriberKey(EmailAddress): " + resultListSub.SubscriberKey); } } #if false var filterDate = new DateTime(2013, 1, 15, 13, 0, 0); Console.WriteLine("Retrieve Filtered ListSubscribers with GetMoreResults"); var oe2 = new ET_List_Subscriber { AuthStub = myclient, SearchFilter = new SimpleFilterPart { Property = "EventDate", SimpleOperator = SimpleOperators.greaterThan, DateValue = new [] { filterDate } }, Props = new [] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" }, }; var oeGet = oe2.Get(); Console.WriteLine("Get Status: " + oeGet.Status.ToString()); Console.WriteLine("Message: " + oeGet.Message); Console.WriteLine("Code: " + oeGet.Code.ToString()); Console.WriteLine("Results Length: " + oeGet.Results.Length); Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString()); // Since this could potentially return a large number of results, we do not want to print the results //foreach (ET_ListSubscriber ListSubscriber in oeGet.Results) // Console.WriteLine("SubscriberKey: " + ListSubscriber.SubscriberKey + ", EventDate: " + ListSubscriber.EventDate.ToString()); while (oeGet.MoreResults) { Console.WriteLine("Continue Retrieve Filtered ListSubscribers with GetMoreResults"); oeGet = oe2.GetMoreResults(); Console.WriteLine("Get Status: " + oeGet.Status.ToString()); Console.WriteLine("Message: " + oeGet.Message); Console.WriteLine("Code: " + oeGet.Code.ToString()); Console.WriteLine("Results Length: " + oeGet.Results.Length); Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString()); } // The following request could potentially bring back large amounts of data if run against a production account Console.WriteLine("Retrieve All ListSubscribers with GetMoreResults"); var oe3 = new ET_List_Subscriber { AuthStub = myclient, Props = new string[] { "SendID", "SubscriberKey", "EventDate", "Client.ID", "EventType", "BatchID", "TriggeredSendDefinitionObjectID", "PartnerKey" }, }; var oeGetAll = oe3.Get(); Console.WriteLine("Get Status: " + oeGetAll.Status.ToString()); Console.WriteLine("Message: " + oeGetAll.Message); Console.WriteLine("Code: " + oeGetAll.Code.ToString()); Console.WriteLine("Results Length: " + oeGetAll.Results.Length); Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString()); // Since this could potentially return a large number of results, we do not want to print the results foreach (ET_List_Subscriber ListSubscriber in oeGetAll.Results) { Console.WriteLine("SubscriberKey: " + ListSubscriber.SubscriberKey + ", EventDate: " + ListSubscriber.EventDate.ToString()); } while (oeGetAll.MoreResults) { oeGetAll = oe3.GetMoreResults(); Console.WriteLine("Get Status: " + oeGetAll.Status.ToString()); Console.WriteLine("Message: " + oeGetAll.Message); Console.WriteLine("Code: " + oeGetAll.Code.ToString()); Console.WriteLine("Results Length: " + oeGetAll.Results.Length); Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString()); } #endif }
static void TestET_Folder() { string NewFolderName = "Testing C Sharp SDK"; int ParentIDForEmail = 0; string ContentType = "email"; ET_Client myclient = new ET_Client(); Console.WriteLine("--- Testing Folder ---"); Console.WriteLine("\n Retrieve All Folder with GetMoreResults"); ET_Folder getAllFolder = new ET_Folder(); getAllFolder.AuthStub = myclient; getAllFolder.Props = new string[] { "ID", "Client.ID", "ParentFolder.ID", "ParentFolder.CustomerKey", "ParentFolder.ObjectID", "ParentFolder.Name", "ParentFolder.Description", "ParentFolder.ContentType", "ParentFolder.IsActive", "ParentFolder.IsEditable", "ParentFolder.AllowChildren", "Name", "Description", "ContentType", "IsActive", "IsEditable", "AllowChildren", "CreatedDate", "ModifiedDate", "Client.ModifiedBy", "ObjectID", "CustomerKey", "Client.EnterpriseID", "Client.CreatedBy" }; GetReturn grAllFolder = getAllFolder.Get(); Console.WriteLine("Get Status: " + grAllFolder.Status.ToString()); Console.WriteLine("Message: " + grAllFolder.Message.ToString()); Console.WriteLine("Code: " + grAllFolder.Code.ToString()); Console.WriteLine("Results Length: " + grAllFolder.Results.Length); while (grAllFolder.MoreResults) { Console.WriteLine("\n Continue Retrieve All Folders with GetMoreResults"); grAllFolder = getAllFolder.GetMoreResults(); Console.WriteLine("Get Status: " + grAllFolder.Status.ToString()); Console.WriteLine("Message: " + grAllFolder.Message.ToString()); Console.WriteLine("Code: " + grAllFolder.Code.ToString()); Console.WriteLine("Results Length: " + grAllFolder.Results.Length); } Console.WriteLine("\n Retrieve Specific Folder for Email Folder ParentID"); ET_Folder getFolder = new ET_Folder(); getFolder.AuthStub = myclient; SimpleFilterPart ParentFolderFilter = new SimpleFilterPart() { Property = "ParentFolder.ID", SimpleOperator = SimpleOperators.equals, Value = new string[] { "0" } }; SimpleFilterPart ContentTypeFilter = new SimpleFilterPart() { Property = "ContentType", SimpleOperator = SimpleOperators.equals, Value = new string[] { "Email" } }; getFolder.SearchFilter = new ComplexFilterPart() { LeftOperand = ParentFolderFilter, RightOperand = ContentTypeFilter, LogicalOperator = LogicalOperators.AND }; getFolder.Props = new string[] { "ID", "Name", "Description" }; GetReturn grFolder = getFolder.Get(); Console.WriteLine("Get Status: " + grFolder.Status.ToString()); Console.WriteLine("Message: " + grFolder.Message.ToString()); Console.WriteLine("Code: " + grFolder.Code.ToString()); Console.WriteLine("Results Length: " + grFolder.Results.Length); foreach (ET_Folder ef in grFolder.Results) { ParentIDForEmail = ef.ID; } if (ParentIDForEmail != 0) { Console.WriteLine("\n Create Folder"); ET_Folder fold = new ET_Folder(); fold.Name = NewFolderName; fold.Description = NewFolderName; fold.CustomerKey = NewFolderName; fold.AuthStub = myclient; fold.ParentFolder = new ET_Folder(); fold.ParentFolder.ID = ParentIDForEmail; fold.ContentType = ContentType; fold.IsEditable = true; PostReturn prFolder = fold.Post(); Console.WriteLine("Post Status: " + prFolder.Status.ToString()); Console.WriteLine("Message: " + prFolder.Message.ToString()); Console.WriteLine("Code: " + prFolder.Code.ToString()); Console.WriteLine("Results Length: " + prFolder.Results.Length); foreach (ResultDetail rd in prFolder.Results) { Console.WriteLine("--Status Code: " + rd.StatusCode); Console.WriteLine("--Status Message: " + rd.StatusMessage); } Console.WriteLine("\n Retrieve newly created Folder"); ET_Folder getNewFolder = new ET_Folder(); getNewFolder.AuthStub = myclient; getNewFolder.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { NewFolderName } }; getNewFolder.Props = new string[] { "ID", "Name", "Description" }; GetReturn grNewFolder = getNewFolder.Get(); Console.WriteLine("Get Status: " + grNewFolder.Status.ToString()); Console.WriteLine("Message: " + grFolder.Message.ToString()); Console.WriteLine("Code: " + grNewFolder.Code.ToString()); Console.WriteLine("Results Length: " + grNewFolder.Results.Length); foreach (ET_Folder ef in grNewFolder.Results) { Console.WriteLine("--Name: " + ef.Name + " - Description:" + ef.Description); } Console.WriteLine("\n UpdateFolder"); ET_Folder patchFolder = new ET_Folder(); patchFolder.AuthStub = myclient; patchFolder.CustomerKey = NewFolderName; patchFolder.Description = "Now with a new Description"; PatchReturn patchResponse = patchFolder.Patch(); Console.WriteLine("Patch Status: " + patchResponse.Status.ToString()); Console.WriteLine("Message: " + patchResponse.Message.ToString()); Console.WriteLine("Code: " + patchResponse.Code.ToString()); Console.WriteLine("Results Length: " + patchResponse.Results.Length); if (patchResponse.Status) { Console.WriteLine("\n Retrieve updated Folder"); grNewFolder = getNewFolder.Get(); Console.WriteLine("Get Status: " + grNewFolder.Status.ToString()); Console.WriteLine("Message: " + grFolder.Message.ToString()); Console.WriteLine("Code: " + grNewFolder.Code.ToString()); Console.WriteLine("Results Length: " + grNewFolder.Results.Length); foreach (ET_Folder ef in grNewFolder.Results) { Console.WriteLine("--Name: " + ef.Name + " - Description:" + ef.Description); } } Console.WriteLine("\n Delete Folder"); ET_Folder delFolder = new ET_Folder(); delFolder.AuthStub = myclient; delFolder.CustomerKey = NewFolderName; FuelSDK.DeleteReturn drFolder = delFolder.Delete(); Console.WriteLine("Delete Status: " + drFolder.Status.ToString()); Console.WriteLine("Message: " + drFolder.Message.ToString()); Console.WriteLine("Code: " + drFolder.Code.ToString()); Console.WriteLine("Results Length: " + drFolder.Results.Length); foreach (ResultDetail rd in drFolder.Results) { Console.WriteLine("--Status Code: " + rd.StatusCode); Console.WriteLine("--Status Message: " + rd.StatusMessage); } Console.WriteLine("\n Retrieve Folder to confirm deletion"); grNewFolder = getNewFolder.Get(); Console.WriteLine("Get Status: " + grNewFolder.Status.ToString()); Console.WriteLine("Message: " + grFolder.Message.ToString()); Console.WriteLine("Code: " + grNewFolder.Code.ToString()); Console.WriteLine("Results Length: " + grNewFolder.Results.Length); foreach (ET_Folder ef in grNewFolder.Results) { Console.WriteLine("--Name: " + ef.Name + " - Description:" + ef.Description); } } }
static void TestET_DataExtension() { ET_Client myclient = new ET_Client(); string NameOfTestDataExtension = "CSharpCreatedDE"; Console.WriteLine("--- Testing DataExtension ---"); Console.WriteLine("\n Get all of the DataExtensions in an Account"); ET_DataExtension getAllDataExtension = new ET_DataExtension(); getAllDataExtension.AuthStub = myclient; getAllDataExtension.Props = new string[] { "CustomerKey", "Name" }; GetReturn grAllDataExtension = getAllDataExtension.Get(); Console.WriteLine("Get Status: " + grAllDataExtension.Status.ToString()); Console.WriteLine("Message: " + grAllDataExtension.Message.ToString()); Console.WriteLine("Code: " + grAllDataExtension.Code.ToString()); Console.WriteLine("Results Length: " + grAllDataExtension.Results.Length); while (grAllDataExtension.MoreResults) { Console.WriteLine("\n Continue Retrieve All DataExtension with GetMoreResults"); grAllDataExtension = getAllDataExtension.GetMoreResults(); Console.WriteLine("Get Status: " + grAllDataExtension.Status.ToString()); Console.WriteLine("Message: " + grAllDataExtension.Message.ToString()); Console.WriteLine("Code: " + grAllDataExtension.Code.ToString()); Console.WriteLine("Results Length: " + grAllDataExtension.Results.Length); } Console.WriteLine("\n Create DataExtension"); ET_DataExtension postDataExtension = new ET_DataExtension(); postDataExtension.AuthStub = myclient; postDataExtension.Name = NameOfTestDataExtension; postDataExtension.CustomerKey = NameOfTestDataExtension; ET_DataExtensionColumn nameColumn = new ET_DataExtensionColumn() { Name = "Name", FieldType = DataExtensionFieldType.Text, IsPrimaryKey = true, MaxLength = 100, IsRequired = true }; ET_DataExtensionColumn otherColumn = new ET_DataExtensionColumn() { Name = "OtherColumn", FieldType = DataExtensionFieldType.Text }; postDataExtension.Columns = new ET_DataExtensionColumn[] { nameColumn, otherColumn }; PostReturn postResponse = postDataExtension.Post(); Console.WriteLine("Post Status: " + postResponse.Status.ToString()); Console.WriteLine("Message: " + postResponse.Message.ToString()); Console.WriteLine("Code: " + postResponse.Code.ToString()); Console.WriteLine("Results Length: " + postResponse.Results.Length); if (postResponse.Status) { Console.WriteLine("\n Update DE to add new field"); ET_DataExtension patchDataExtension = new ET_DataExtension(); patchDataExtension.AuthStub = myclient; patchDataExtension.CustomerKey = NameOfTestDataExtension; ET_DataExtensionColumn addedField = new ET_DataExtensionColumn() { Name = "AddedField", FieldType = DataExtensionFieldType.Text }; patchDataExtension.Columns = new ET_DataExtensionColumn[] { addedField }; FuelSDK.PatchReturn patchFR = patchDataExtension.Patch(); Console.WriteLine("Patch Status: " + patchFR.Status.ToString()); Console.WriteLine("Message: " + patchFR.Message.ToString()); Console.WriteLine("Code: " + patchFR.Code.ToString()); Console.WriteLine("Results Length: " + patchFR.Results.Length); Console.WriteLine("\n Retrieve All Columns for a data extension"); ET_DataExtensionColumn getColumn = new ET_DataExtensionColumn(); getColumn.AuthStub = myclient; getColumn.Props = new string[] { "Name", "FieldType" }; getColumn.SearchFilter = new SimpleFilterPart() { Property = "DataExtension.CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { NameOfTestDataExtension } }; GetReturn getColumnResponse = getColumn.Get(); Console.WriteLine("Get Status: " + getColumnResponse.Status.ToString()); Console.WriteLine("Message: " + getColumnResponse.Message.ToString()); Console.WriteLine("Code: " + getColumnResponse.Code.ToString()); Console.WriteLine("Results Length: " + getColumnResponse.Results.Length); if (getColumnResponse.Status) { foreach (ET_DataExtensionColumn column in getColumnResponse.Results) { Console.WriteLine("-- Name: " + column.Name + " Type: " + column.FieldType.ToString()); } } Console.WriteLine("\n Add a row to a data extension (using CustomerKey)"); ET_DataExtensionRow deRowPost = new ET_DataExtensionRow(); deRowPost.AuthStub = myclient; deRowPost.DataExtensionCustomerKey = NameOfTestDataExtension; deRowPost.ColumnValues.Add("Name", "Example Name"); deRowPost.ColumnValues.Add("OtherColumn", "Different Example Text"); PostReturn prRowResponse = deRowPost.Post(); Console.WriteLine("Post Status: " + prRowResponse.Status.ToString()); Console.WriteLine("Message: " + prRowResponse.Message.ToString()); Console.WriteLine("Code: " + prRowResponse.Code.ToString()); Console.WriteLine("Results Length: " + prRowResponse.Results.Length); Console.WriteLine("\n Add a row to a data extension (using Name)"); ET_DataExtensionRow deRowPost2 = new ET_DataExtensionRow(); deRowPost2.AuthStub = myclient; deRowPost2.DataExtensionName = NameOfTestDataExtension; deRowPost2.ColumnValues.Add("Name", "Example Name3"); deRowPost2.ColumnValues.Add("OtherColumn", "Different Example Text"); PostReturn prRowResponse2 = deRowPost2.Post(); Console.WriteLine("Post Status: " + prRowResponse2.Status.ToString()); Console.WriteLine("Message: " + prRowResponse2.Message.ToString()); Console.WriteLine("Code: " + prRowResponse2.Code.ToString()); Console.WriteLine("Results Length: " + prRowResponse2.Results.Length); Console.WriteLine("\n Retrieve All Rows from DataExtension"); ET_DataExtensionRow deRowGet = new ET_DataExtensionRow(); deRowGet.AuthStub = myclient; deRowGet.DataExtensionName = NameOfTestDataExtension; deRowGet.Props = new string[] { "Name", "OtherColumn" }; GetReturn grRow = deRowGet.Get(); Console.WriteLine("Post Status: " + grRow.Status.ToString()); Console.WriteLine("Message: " + grRow.Message.ToString()); Console.WriteLine("Code: " + grRow.Code.ToString()); Console.WriteLine("Results Length: " + grRow.Results.Length); if (getColumnResponse.Status) { foreach (ET_DataExtensionRow column in grRow.Results) { Console.WriteLine("--Name: " + column.ColumnValues["Name"] + " - OtherColumn: " + column.ColumnValues["OtherColumn"]); } } Console.WriteLine("\n Update a row in a data extension"); ET_DataExtensionRow deRowPatch = new ET_DataExtensionRow(); deRowPatch.AuthStub = myclient; deRowPatch.DataExtensionCustomerKey = NameOfTestDataExtension; deRowPatch.ColumnValues.Add("Name", "Example Name"); deRowPatch.ColumnValues.Add("OtherColumn", "New Value for First Column"); PatchReturn patchRowResponse = deRowPatch.Patch(); Console.WriteLine("Post Status: " + patchRowResponse.Status.ToString()); Console.WriteLine("Message: " + patchRowResponse.Message.ToString()); Console.WriteLine("Code: " + patchRowResponse.Code.ToString()); Console.WriteLine("Results Length: " + patchRowResponse.Results.Length); Console.WriteLine("\n Retrieve only updated row"); ET_DataExtensionRow deRowGetSingle = new ET_DataExtensionRow(); deRowGetSingle.AuthStub = myclient; deRowGetSingle.DataExtensionName = NameOfTestDataExtension; deRowGetSingle.Props = new string[] { "Name", "OtherColumn" }; deRowGetSingle.SearchFilter = new SimpleFilterPart() { Property = "Name", SimpleOperator = SimpleOperators.equals, Value = new string[] { "Example Name" } }; GetReturn grSingleRow = deRowGetSingle.Get(); Console.WriteLine("Post Status: " + grSingleRow.Status.ToString()); Console.WriteLine("Message: " + grSingleRow.Message.ToString()); Console.WriteLine("Code: " + grSingleRow.Code.ToString()); Console.WriteLine("Results Length: " + grSingleRow.Results.Length); if (getColumnResponse.Status) { foreach (ET_DataExtensionRow column in grSingleRow.Results) { Console.WriteLine("--Name: " + column.ColumnValues["Name"] + " - OtherColumn: " + column.ColumnValues["OtherColumn"]); } } Console.WriteLine("\n Delete a row from a data extension)"); ET_DataExtensionRow deRowDelete = new ET_DataExtensionRow(); deRowDelete.AuthStub = myclient; deRowDelete.DataExtensionCustomerKey = NameOfTestDataExtension; deRowDelete.ColumnValues.Add("Name", "Example Name"); DeleteReturn drRowResponse = deRowDelete.Delete(); Console.WriteLine("Post Status: " + drRowResponse.Status.ToString()); Console.WriteLine("Message: " + drRowResponse.Message.ToString()); Console.WriteLine("Code: " + drRowResponse.Code.ToString()); Console.WriteLine("Results Length: " + drRowResponse.Results.Length); Console.WriteLine("\n Delete DataExtension"); ET_DataExtension delDataExtension = new ET_DataExtension(); delDataExtension.CustomerKey = NameOfTestDataExtension; delDataExtension.AuthStub = myclient; DeleteReturn deleteResponse = delDataExtension.Delete(); Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString()); Console.WriteLine("Message: " + deleteResponse.Message.ToString()); Console.WriteLine("Code: " + deleteResponse.Code.ToString()); Console.WriteLine("Results Length: " + deleteResponse.Results.Length); Console.WriteLine("\n Info DataExtension"); ET_DataExtension DataExtensionInfo = new ET_DataExtension(); DataExtensionInfo.AuthStub = myclient; InfoReturn info = DataExtensionInfo.Info(); Console.WriteLine("Info Status: " + info.Status.ToString()); Console.WriteLine("Message: " + info.Message.ToString()); Console.WriteLine("Code: " + info.Code.ToString()); Console.WriteLine("Results Length: " + info.Results.Length); foreach (ET_PropertyDefinition def in info.Results) { Console.WriteLine("--Name: " + def.Name + ", IsRetrievable: " + def.IsRetrievable.ToString()); } } }
static void TestET_Subscriber() { ET_Client myclient = new ET_Client(); Console.WriteLine("--- Testing Subscriber ---"); string SubscriberTestEmail = "*****@*****.**"; Console.WriteLine("\n Create Subscriber"); ET_Subscriber postSub = new ET_Subscriber(); postSub.AuthStub = myclient; postSub.EmailAddress = SubscriberTestEmail; postSub.Attributes = new FuelSDK.ET_ProfileAttribute[] { new ET_ProfileAttribute() { Name = "First Name", Value = "ExactTarget Example" } }; PostReturn postResponse = postSub.Post(); Console.WriteLine("Post Status: " + postResponse.Status.ToString()); Console.WriteLine("Message: " + postResponse.Message.ToString()); Console.WriteLine("Code: " + postResponse.Code.ToString()); Console.WriteLine("Results Length: " + postResponse.Results.Length); if (postResponse.Results.Length > 0) { Console.WriteLine("--NewID: " + postResponse.Results[0].NewID.ToString()); foreach (ET_ProfileAttribute attr in ((ET_Subscriber)postResponse.Results[0].Object).Attributes) { Console.WriteLine("Name: " + attr.Name + ", Value: " + attr.Value); } } Console.WriteLine("\n Retrieve newly created Subscriber"); ET_Subscriber getSub = new ET_Subscriber(); getSub.AuthStub = myclient; getSub.Props = new string[] { "SubscriberKey", "EmailAddress", "Status" }; getSub.SearchFilter = new SimpleFilterPart() { Property = "SubscriberKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { SubscriberTestEmail } }; GetReturn getResponse = getSub.Get(); Console.WriteLine("Get Status: " + getResponse.Status.ToString()); Console.WriteLine("Message: " + getResponse.Message.ToString()); Console.WriteLine("Code: " + getResponse.Code.ToString()); Console.WriteLine("Results Length: " + getResponse.Results.Length); foreach (ET_Subscriber sub in getResponse.Results) { Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString()); } Console.WriteLine("\n Update Subscriber"); ET_Subscriber patchSub = new ET_Subscriber(); patchSub.AuthStub = myclient; patchSub.EmailAddress = SubscriberTestEmail; patchSub.Status = SubscriberStatus.Unsubscribed; patchSub.Attributes = new FuelSDK.ET_ProfileAttribute[] { new ET_ProfileAttribute() { Name = "First Name", Value = "ExactTarget Example" } }; PatchReturn pathResponse = patchSub.Patch(); Console.WriteLine("Patch Status: " + pathResponse.Status.ToString()); Console.WriteLine("Message: " + pathResponse.Message.ToString()); Console.WriteLine("Code: " + pathResponse.Code.ToString()); Console.WriteLine("Results Length: " + pathResponse.Results.Length); foreach (ResultDetail rd in pathResponse.Results) { ET_Subscriber sub = (ET_Subscriber)rd.Object; Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString()); } Console.WriteLine("\n Retrieve Subscriber that should have status unsubscribed now"); getResponse = getSub.Get(); Console.WriteLine("Get Status: " + getResponse.Status.ToString()); Console.WriteLine("Message: " + getResponse.Message.ToString()); Console.WriteLine("Code: " + getResponse.Code.ToString()); Console.WriteLine("Results Length: " + getResponse.Results.Length); foreach (ET_Subscriber sub in getResponse.Results) { Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString()); } Console.WriteLine("\n Delete Subscriber"); ET_Subscriber deleteSub = new ET_Subscriber(); deleteSub.AuthStub = myclient; deleteSub.EmailAddress = SubscriberTestEmail; DeleteReturn deleteResponse = deleteSub.Delete(); Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString()); Console.WriteLine("Message: " + deleteResponse.Message.ToString()); Console.WriteLine("Code: " + deleteResponse.Code.ToString()); Console.WriteLine("Results Length: " + deleteResponse.Results.Length); Console.WriteLine("\n Retrieve Subscriber to confirm deletion"); getResponse = getSub.Get(); Console.WriteLine("Get Status: " + getResponse.Status.ToString()); Console.WriteLine("Message: " + getResponse.Message.ToString()); Console.WriteLine("Code: " + getResponse.Code.ToString()); Console.WriteLine("Results Length: " + getResponse.Results.Length); foreach (ET_Subscriber sub in getResponse.Results) { Console.WriteLine("--EmailAddress: " + sub.EmailAddress + " Status: " + sub.Status.ToString()); } }
static void TestET_TriggeredSend() { ET_Client myclient = new ET_Client(); Console.WriteLine("--- Testing TriggeredSend ---"); string TSNameForCreateThenDelete = Guid.NewGuid().ToString(); string ExistingTSDCustomerKey = "TEXTEXT"; Console.WriteLine("\n Send Using an Existing Definition "); ET_TriggeredSend tsdSend = new ET_TriggeredSend(); tsdSend.AuthStub = myclient; tsdSend.CustomerKey = ExistingTSDCustomerKey; tsdSend.Subscribers = new ET_Subscriber[] { new ET_Subscriber() { EmailAddress = "*****@*****.**", SubscriberKey = "*****@*****.**" } }; SendReturn srSend = tsdSend.Send(); Console.WriteLine("Send Status: " + srSend.Status.ToString()); Console.WriteLine("Message: " + srSend.Message.ToString()); Console.WriteLine("Code: " + srSend.Code.ToString()); Console.WriteLine("Results Length: " + srSend.Results.Length); Console.WriteLine("\n Retrieve All TriggeredSend Definitions"); ET_TriggeredSend tsdGetAll = new ET_TriggeredSend(); tsdGetAll.AuthStub = myclient; tsdGetAll.Props = new string[] { "CustomerKey", "Name", "TriggeredSendStatus" }; tsdGetAll.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { TSNameForCreateThenDelete } }; GetReturn grAllTSD = tsdGetAll.Get(); Console.WriteLine("Get Status: " + grAllTSD.Status.ToString()); Console.WriteLine("Message: " + grAllTSD.Message.ToString()); Console.WriteLine("Code: " + grAllTSD.Code.ToString()); Console.WriteLine("Results Length: " + grAllTSD.Results.Length); foreach (ET_TriggeredSend result in grAllTSD.Results) { Console.WriteLine("--CustomerKey: " + result.CustomerKey + ", Name: " + result.Name + ", Status: " + result.TriggeredSendStatus.ToString()); } Console.WriteLine("\n Create a TriggeredSend Definition"); ET_TriggeredSend tsd = new ET_TriggeredSend(); tsd.AuthStub = myclient; tsd.Name = TSNameForCreateThenDelete; tsd.CustomerKey = TSNameForCreateThenDelete; tsd.Email = new ET_Email() { ID = 3113962 }; tsd.SendClassification = new ET_SendClassification() { CustomerKey = "2240" }; PostReturn prTSD = tsd.Post(); Console.WriteLine("Post Status: " + prTSD.Status.ToString()); Console.WriteLine("Message: " + prTSD.Message.ToString()); Console.WriteLine("Code: " + prTSD.Code.ToString()); Console.WriteLine("Results Length: " + prTSD.Results.Length); Console.WriteLine("\n Retrieve Single TriggeredSend"); ET_TriggeredSend tsdGet = new ET_TriggeredSend(); tsdGet.AuthStub = myclient; tsdGet.Props = new string[] { "CustomerKey", "Name", "TriggeredSendStatus" }; tsdGet.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { TSNameForCreateThenDelete } }; GetReturn tsdGetSingle = tsdGet.Get(); Console.WriteLine("Get Status: " + tsdGetSingle.Status.ToString()); Console.WriteLine("Message: " + tsdGetSingle.Message.ToString()); Console.WriteLine("Code: " + tsdGetSingle.Code.ToString()); Console.WriteLine("Results Length: " + tsdGetSingle.Results.Length); foreach (ET_TriggeredSend result in tsdGetSingle.Results) { Console.WriteLine("--CustomerKey: " + result.CustomerKey + ", Name: " + result.Name + ", Status: " + result.TriggeredSendStatus.ToString()); } Console.WriteLine("\n Start a TriggeredSend by setting to Active"); ET_TriggeredSend tsdPatch = new ET_TriggeredSend(); tsdPatch.AuthStub = myclient; tsdPatch.CustomerKey = TSNameForCreateThenDelete; tsdPatch.TriggeredSendStatus = TriggeredSendStatusEnum.Active; PatchReturn patchrTSD = tsdPatch.Patch(); Console.WriteLine("Patch Status: " + patchrTSD.Status.ToString()); Console.WriteLine("Message: " + patchrTSD.Message.ToString()); Console.WriteLine("Code: " + patchrTSD.Code.ToString()); Console.WriteLine("Results Length: " + patchrTSD.Results.Length); Console.WriteLine("\n Retrieve Single TriggeredSend After setting to active"); tsdGetSingle = tsdGet.Get(); Console.WriteLine("Get Status: " + tsdGetSingle.Status.ToString()); Console.WriteLine("Message: " + tsdGetSingle.Message.ToString()); Console.WriteLine("Code: " + tsdGetSingle.Code.ToString()); Console.WriteLine("Results Length: " + tsdGetSingle.Results.Length); foreach (ET_TriggeredSend result in tsdGetSingle.Results) { Console.WriteLine("--CustomerKey: " + result.CustomerKey + ", Name: " + result.Name + ", Status: " + result.TriggeredSendStatus.ToString()); } Console.WriteLine("\n Send using new definition"); ET_TriggeredSend tsdSendNew = new ET_TriggeredSend(); tsdSendNew.AuthStub = myclient; tsdSendNew.CustomerKey = TSNameForCreateThenDelete; tsdSendNew.Subscribers = new ET_Subscriber[] { new ET_Subscriber() { EmailAddress = "*****@*****.**", SubscriberKey = "*****@*****.**" } }; SendReturn srSendnew = tsdSendNew.Send(); Console.WriteLine("Send Status: " + srSendnew.Status.ToString()); Console.WriteLine("Message: " + srSendnew.Message.ToString()); Console.WriteLine("Code: " + srSendnew.Code.ToString()); Console.WriteLine("Results Length: " + srSendnew.Results.Length); Console.WriteLine("\n Pause a TriggeredSend by setting to Inactive"); tsdPatch.TriggeredSendStatus = TriggeredSendStatusEnum.Inactive; patchrTSD = tsdPatch.Patch(); Console.WriteLine("Patch Status: " + patchrTSD.Status.ToString()); Console.WriteLine("Message: " + patchrTSD.Message.ToString()); Console.WriteLine("Code: " + patchrTSD.Code.ToString()); Console.WriteLine("Results Length: " + patchrTSD.Results.Length); Console.WriteLine("\n Delete a TriggeredSend Definition"); ET_TriggeredSend tsdDelete = new ET_TriggeredSend(); tsdDelete.AuthStub = myclient; tsdDelete.CustomerKey = TSNameForCreateThenDelete; DeleteReturn drTSD = tsdDelete.Delete(); Console.WriteLine("Delete Status: " + drTSD.Status.ToString()); Console.WriteLine("Message: " + drTSD.Message.ToString()); Console.WriteLine("Code: " + drTSD.Code.ToString()); Console.WriteLine("Results Length: " + drTSD.Results.Length); }
static void TestET_ListSubscriber() { string NewListName = "CSharpSDKListSubscriber"; string SubscriberTestEmail = "*****@*****.**"; Console.WriteLine("--- Testing ListSubscriber ---"); ET_Client myclient = new ET_Client(); Console.WriteLine("\n Create List"); ET_List postList = new ET_List(); postList.AuthStub = myclient; postList.ListName = NewListName; PostReturn prList = postList.Post(); if (prList.Status && prList.Results.Length > 0) { int newListID = prList.Results[0].Object.ID; Console.WriteLine("\n Create Subscriber on List"); ET_Subscriber postSub = new ET_Subscriber(); postSub.Lists = new ET_SubscriberList[] { new ET_SubscriberList() { ID = newListID } }; postSub.AuthStub = myclient; postSub.EmailAddress = SubscriberTestEmail; postSub.Attributes = new FuelSDK.ET_ProfileAttribute[] { new ET_ProfileAttribute() { Name = "First Name", Value = "ExactTarget Example" } }; PostReturn postResponse = postSub.Post(); Console.WriteLine("Post Status: " + postResponse.Status.ToString()); Console.WriteLine("Message: " + postResponse.Message.ToString()); Console.WriteLine("Code: " + postResponse.Code.ToString()); Console.WriteLine("Results Length: " + postResponse.Results.Length); if (!postResponse.Status) { if (postResponse.Results.Length > 0 && postResponse.Results[0].ErrorCode == 12014) { // If the subscriber already exists in the account then we need to do an update. //Update Subscriber On List Console.WriteLine("\n Update Subscriber to add to List"); PatchReturn patchResponse = postSub.Patch(); Console.WriteLine("Post Status: " + patchResponse.Status.ToString()); Console.WriteLine("Message: " + patchResponse.Message.ToString()); Console.WriteLine("Code: " + patchResponse.Code.ToString()); Console.WriteLine("Results Length: " + patchResponse.Results.Length); } } Console.WriteLine("\n Retrieve all Subscribers on the List"); ET_List_Subscriber getListSub = new ET_List_Subscriber(); getListSub.AuthStub = myclient; getListSub.Props = new string[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" }; getListSub.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { newListID.ToString() } }; GetReturn getResponse = getListSub.Get(); Console.WriteLine("Get Status: " + getResponse.Status.ToString()); Console.WriteLine("Message: " + getResponse.Message.ToString()); Console.WriteLine("Code: " + getResponse.Code.ToString()); Console.WriteLine("Results Length: " + getResponse.Results.Length); foreach (ET_List_Subscriber ResultListSub in getResponse.Results) { Console.WriteLine("--ListID: " + ResultListSub.ID + ", SubscriberKey(EmailAddress): " + ResultListSub.SubscriberKey); } } //Console.WriteLine("Retrieve Filtered ListSubscribers with GetMoreResults"); //ET_ListSubscriber oe = new ET_ListSubscriber(); //oe.authStub = myclient; //oe.SearchFilter = new SimpleFilterPart() { Property = "EventDate", SimpleOperator = SimpleOperators.greaterThan, DateValue = new DateTime[] { filterDate } }; //oe.props = new string[] { "ObjectID", "SubscriberKey", "CreatedDate", "Client.ID", "Client.PartnerClientKey", "ListID", "Status" }; //GetReturn oeGet = oe.Get(); //Console.WriteLine("Get Status: " + oeGet.Status.ToString()); //Console.WriteLine("Message: " + oeGet.Message.ToString()); //Console.WriteLine("Code: " + oeGet.Code.ToString()); //Console.WriteLine("Results Length: " + oeGet.Results.Length); //Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString()); //// Since this could potentially return a large number of results, we do not want to print the results ////foreach (ET_ListSubscriber ListSubscriber in oeGet.Results) ////{ //// Console.WriteLine("SubscriberKey: " + ListSubscriber.SubscriberKey + ", EventDate: " + ListSubscriber.EventDate.ToString()); ////} //while (oeGet.MoreResults) //{ // Console.WriteLine("Continue Retrieve Filtered ListSubscribers with GetMoreResults"); // oeGet = oe.GetMoreResults(); // Console.WriteLine("Get Status: " + oeGet.Status.ToString()); // Console.WriteLine("Message: " + oeGet.Message.ToString()); // Console.WriteLine("Code: " + oeGet.Code.ToString()); // Console.WriteLine("Results Length: " + oeGet.Results.Length); // Console.WriteLine("MoreResults: " + oeGet.MoreResults.ToString()); //} //The following request could potentially bring back large amounts of data if run against a production account //Console.WriteLine("Retrieve All ListSubscribers with GetMoreResults"); //ET_ListSubscriber oe = new ET_ListSubscriber(); //oe.authStub = myclient; //oe.props = new string[] { "SendID", "SubscriberKey", "EventDate", "Client.ID", "EventType", "BatchID", "TriggeredSendDefinitionObjectID", "PartnerKey" }; //GetResponse oeGetAll = oe.Get(); //Console.WriteLine("Get Status: " + oeGetAll.Status.ToString()); //Console.WriteLine("Message: " + oeGetAll.Message.ToString()); //Console.WriteLine("Code: " + oeGetAll.Code.ToString()); //Console.WriteLine("Results Length: " + oeGetAll.Results.Length); //Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString()); //// Since this could potentially return a large number of results, we do not want to print the results ////foreach (ET_ListSubscriber ListSubscriber in oeGet.Results) ////{ //// Console.WriteLine("SubscriberKey: " + ListSubscriber.SubscriberKey + ", EventDate: " + ListSubscriber.EventDate.ToString()); ////} //while (oeGetAll.MoreResults) //{ // oeGetAll = oe.GetMoreResults(); // Console.WriteLine("Get Status: " + oeGetAll.Status.ToString()); // Console.WriteLine("Message: " + oeGetAll.Message.ToString()); // Console.WriteLine("Code: " + oeGetAll.Code.ToString()); // Console.WriteLine("Results Length: " + oeGetAll.Results.Length); // Console.WriteLine("MoreResults: " + oeGetAll.MoreResults.ToString()); //} }