/// <summary> /// Main Crawl method /// </summary> /// <param name="mid"></param> public void Crawl(ET_Client client) { RetrieveFolderStructure("0", client, "email", ""); RetrieveFolderStructure("0", client, "dataextension", ""); RetrieveFolderStructure("0", client, "media", ""); RetrieveFolderStructure("0", client, "content", ""); }
// ------------------------------------------------------------ // Name: CUtilities // Abstract: Constructor // ------------------------------------------------------------ static CExactTargetUtilities() { // Initialize our ET Client // Pass ClientID/ClientSecret NameValueCollection parameters = new NameValueCollection(); //parameters.Add("clientId", "<InsertClientId>"); //parameters.Add("clientSecret", "<InsertClientSecret>"); // WORKS FOR Customer Unit Lists parameters.Add("clientId", "<InsertClientId>"); parameters.Add("clientSecret", "<InsertClientSecret>"); // WORKS FOR main subscribers and shared data extensions!! //parameters.Add("clientId", "<InsertClientId>"); //parameters.Add("clientSecret", "<InsertClientSecret>"); Console.WriteLine("ID: " + parameters.Get("clientID").ToString()); m_etcTDClient = new ET_Client(parameters); // for shared data extensions NameValueCollection parametersShared = new NameValueCollection(); parametersShared.Add("clientId", "<InsertClientId>"); parametersShared.Add("clientSecret", "<InsertClientSecret>"); m_etcTDClientShared = new ET_Client(parametersShared); Console.WriteLine("OK"); }
static void TestET_Endpoint() { ET_Client myclient = new ET_Client(); Console.WriteLine("--- Testing Endpoint ---"); Console.WriteLine("\n Retrieve All Endpoints"); ET_Endpoint getEndpoint = new ET_Endpoint(); getEndpoint.AuthStub = myclient; GetReturn grEndpoint = getEndpoint.Get(); Console.WriteLine("Get Status: " + grEndpoint.Status.ToString()); Console.WriteLine("Message: " + grEndpoint.Message.ToString()); Console.WriteLine("Code: " + grEndpoint.Code.ToString()); Console.WriteLine("Results Length: " + grEndpoint.Results.Length); Console.WriteLine("MoreResults: " + grEndpoint.MoreResults.ToString()); Console.WriteLine("\n Retrieve Single Endpoint by Type"); ET_Endpoint getSingleEndpoint = new ET_Endpoint(); getSingleEndpoint.AuthStub = myclient; getSingleEndpoint.Type = "soap"; GetReturn grSingleEndpoint = getSingleEndpoint.Get(); Console.WriteLine("Get Status: " + grSingleEndpoint.Status.ToString()); Console.WriteLine("Message: " + grSingleEndpoint.Message.ToString()); Console.WriteLine("Code: " + grSingleEndpoint.Code.ToString()); Console.WriteLine("Results Length: " + grSingleEndpoint.Results.Length); Console.WriteLine("MoreResults: " + grSingleEndpoint.MoreResults.ToString()); }
public void RetrieveFolderStructure(string id, ET_Client etClient, string contentType, string path) { // Create the SOAP binding for call. BasicHttpBinding binding = new BasicHttpBinding(); binding.Name = "UserNameSoapBinding"; binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; binding.MaxReceivedMessageSize = 2147483647; var client = new FuelSDK.SoapClient(binding, etClient.soapclient.Endpoint.Address); client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; using (var scope = new OperationContextScope(client.InnerChannel)) { // Add oAuth token to SOAP header. XNamespace ns = "http://exacttarget.com"; var oauthElement = new XElement(ns + "oAuthToken", etClient.internalAuthToken); var xmlHeader = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement); OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader); List<object> folders = new List<object>(); String requestID; String status; APIObject[] results; SimpleFilterPart sfp = new SimpleFilterPart(); sfp.Property = "ContentType"; sfp.SimpleOperator = SimpleOperators.equals; sfp.Value = new string[] { contentType }; SimpleFilterPart rf = new SimpleFilterPart(); rf.Property = "ParentFolder.ID"; rf.SimpleOperator = SimpleOperators.equals; rf.Value = new string[] { id }; ComplexFilterPart cfp = new ComplexFilterPart(); cfp.LeftOperand = sfp; cfp.LogicalOperator = LogicalOperators.AND; cfp.RightOperand = rf; RetrieveRequest rr = new RetrieveRequest(); rr.ObjectType = "DataFolder"; rr.Properties = new string[] { "ID", "Name", "ParentFolder.ID", "ParentFolder.Name" }; rr.Filter = cfp; status = client.Retrieve(rr, out requestID, out results); if (results.Count() > 0) { foreach (DataFolder df in results) { RetrieveObjectsByFolderID(df.ID.ToString(), etClient, path + "/" + df.Name + "/", contentType); RetrieveFolderStructure(df.ID.ToString(), etClient, contentType, path + "/" + df.Name + "/"); } } } }
public Conexion() { NameValueCollection parameters = new NameValueCollection(); parameters.Add("clientId", "dvtfti7yw1h1yquvw3rpfh4i"); parameters.Add("clientSecret", "gaHhJaeAnb3q6hPeFGophc2k"); //parameters.Add("jwt", "JWT Value Goes Here"); //parameters.Add("appSignature", "j8hj87jhf54gfk54d2lijs"); ETCliente = new ET_Client(parameters); }
static void Test_CreateDataExtensions() { ET_Client myclient = new ET_Client(); Console.WriteLine("--- Testing CreateDataExtensions ---"); ET_DataExtension DEOne = new ET_DataExtension() {Name = "HelperDEOne",CustomerKey = "HelperDEOne"}; ET_DataExtensionColumn DEOneColumnOne = new ET_DataExtensionColumn() {Name = "Name", FieldType = DataExtensionFieldType.Text, IsPrimaryKey = true, MaxLength = 100, IsRequired = true}; ET_DataExtensionColumn DEOneColumnTwo = new ET_DataExtensionColumn() {Name = "OtherField", FieldType = DataExtensionFieldType.Text}; DEOne.Columns = new ET_DataExtensionColumn[] {DEOneColumnOne, DEOneColumnTwo}; ET_DataExtension DETwo = new ET_DataExtension() {Name = "HelperDETwo",CustomerKey = "HelperDETwo"}; ET_DataExtensionColumn DETwoColumnOne = new ET_DataExtensionColumn() {Name = "Name", FieldType = DataExtensionFieldType.Text, IsPrimaryKey = true, MaxLength = 100, IsRequired = true}; ET_DataExtensionColumn DETwoColumnTwo = new ET_DataExtensionColumn() {Name = "OtherField", FieldType = DataExtensionFieldType.Text}; DETwo.Columns = new ET_DataExtensionColumn[] {DETwoColumnOne, DETwoColumnTwo}; ET_DataExtension[] ACoupleDEs = new ET_DataExtension[] { DEOne, DETwo }; FuelReturn createReturn = myclient.CreateDataExtensions(ACoupleDEs); Console.WriteLine("Helper Status: " + createReturn.Status.ToString()); Console.WriteLine("Message: " + createReturn.Message.ToString()); Console.WriteLine("Code: " + createReturn.Code.ToString()); if (createReturn.Status) { Console.WriteLine("\n Delete DEOne"); ET_DataExtension delDataExtension = new ET_DataExtension(); delDataExtension.CustomerKey = "HelperDEOne"; ; 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 Delete DETwo"); ET_DataExtension delDataExtension2 = new ET_DataExtension(); delDataExtension2.CustomerKey = "HelperDETwo"; ; delDataExtension2.AuthStub = myclient; DeleteReturn deleteResponse2 = delDataExtension2.Delete(); Console.WriteLine("Delete Status: " + deleteResponse2.Status.ToString()); Console.WriteLine("Message: " + deleteResponse2.Message.ToString()); Console.WriteLine("Code: " + deleteResponse2.Code.ToString()); Console.WriteLine("Results Length: " + deleteResponse2.Results.Length); } }
static void Test_AddSubscriberToList() { string NewListName = "CSharpSDKAddSubscriberToList"; string SubscriberTestEmail = "*****@*****.**"; Console.WriteLine("--- Testing AddSubscriberToList ---"); 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"); FuelReturn hrAddSub = myclient.AddSubscribersToList(SubscriberTestEmail, new List<int>() { newListID }); Console.WriteLine("Helper Status: " + hrAddSub.Status.ToString()); Console.WriteLine("Message: " + hrAddSub.Message.ToString()); Console.WriteLine("Code: " + hrAddSub.Code.ToString()); 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.ListID + ", SubscriberKey(EmailAddress): " + ResultListSub.SubscriberKey); } Console.WriteLine("\n Delete List"); postList.ID = newListID; DeleteReturn drList = postList.Delete(); Console.WriteLine("Delete Status: " + drList.Status.ToString()); } }
/// <summary> /// GET /Home/Login called by IMH SSO /// </summary> /// <param name="jwt"></param> /// <returns></returns> public RedirectResult Login(string jwt) { try { if (jwt.Trim().Length > 0) { NameValueCollection parameters = new NameValueCollection(); parameters.Add("jwt", jwt); ET_Client client = new ET_Client(parameters); Session["client"] = client; // Redirect to the application redirectURL specified in App Center. return new RedirectResult("/home/index"); } return new RedirectResult(Request.Url.ToString()); } catch (Exception ex) { throw ex; } }
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()); //} }
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_ContentArea(){ ET_Client myclient = new ET_Client(); string NameOfTestContentArea = "CSharpSDKContentArea"; Console.WriteLine("--- Testing ContentArea ---"); Console.WriteLine("\n Retrieve All ContentArea with GetMoreResults"); ET_ContentArea getAllContentArea = new ET_ContentArea(); getAllContentArea.AuthStub = myclient; getAllContentArea.Props = new string[] { "RowObjectID", "ObjectID", "ID", "CustomerKey", "Client.ID", "ModifiedDate", "CreatedDate", "CategoryID", "Name", "Layout", "IsDynamicContent", "Content", "IsSurvey", "IsBlank", "Key" }; GetReturn grAllContent = getAllContentArea.Get(); Console.WriteLine("Get Status: " + grAllContent.Status.ToString()); Console.WriteLine("Message: " + grAllContent.Message.ToString()); Console.WriteLine("Code: " + grAllContent.Code.ToString()); Console.WriteLine("Results Length: " + grAllContent.Results.Length); while (grAllContent.MoreResults) { Console.WriteLine("\n Continue Retrieve All ContentArea with GetMoreResults"); grAllContent = getAllContentArea.GetMoreResults(); Console.WriteLine("Get Status: " + grAllContent.Status.ToString()); Console.WriteLine("Message: " + grAllContent.Message.ToString()); Console.WriteLine("Code: " + grAllContent.Code.ToString()); Console.WriteLine("Results Length: " + grAllContent.Results.Length); } Console.WriteLine("\n Create ContentArea"); ET_ContentArea postContentArea = new ET_ContentArea(); postContentArea.AuthStub = myclient; postContentArea.Name = NameOfTestContentArea; postContentArea.CustomerKey = NameOfTestContentArea; postContentArea.Content = "<b>Some HTML Content Goes here</b>"; PostReturn postResponse = postContentArea.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 Retrieve newly create ContentArea"); ET_ContentArea getContentArea = new ET_ContentArea(); getContentArea.AuthStub = myclient; getContentArea.Props = new string[] { "RowObjectID","ObjectID","ID","CustomerKey","Client.ID","ModifiedDate","CreatedDate","CategoryID","Name","Layout","IsDynamicContent","Content","IsSurvey","IsBlank","Key" }; getContentArea.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestContentArea } }; GetReturn getResponse = getContentArea.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_ContentArea ResultContentArea in getResponse.Results) { Console.WriteLine("--ID: " + ResultContentArea.ID + ", Name: " + ResultContentArea.Name + ", Content: " + ResultContentArea.Content); } Console.WriteLine("\n Update ContentArea"); ET_ContentArea patchContentArea = new ET_ContentArea(); patchContentArea.CustomerKey = NameOfTestContentArea; patchContentArea.Content = "<b>Some HTML Content Goes here. NOW WITH NEW CONTENT</b>"; patchContentArea.AuthStub = myclient; FuelSDK.PatchReturn patchFR = patchContentArea.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 updated ContentArea"); getContentArea.Props = new string[] { "RowObjectID","ObjectID","ID","CustomerKey","Client.ID","ModifiedDate","CreatedDate","CategoryID","Name","Layout","IsDynamicContent","Content","IsSurvey","IsBlank","Key" }; getContentArea.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestContentArea } }; getResponse = getContentArea.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_ContentArea ResultContentArea in getResponse.Results) { Console.WriteLine("--ID: " + ResultContentArea.ID + ", Name: " + ResultContentArea.Name + ", Content: " + ResultContentArea.Content); } Console.WriteLine("\n Delete ContentArea"); ET_ContentArea delContentArea = new ET_ContentArea(); delContentArea.CustomerKey = NameOfTestContentArea; delContentArea.AuthStub = myclient; DeleteReturn deleteResponse = delContentArea.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 ContentArea to confirm deletion"); getContentArea.Props = new string[] { "RowObjectID","ObjectID","ID","CustomerKey","Client.ID","ModifiedDate","CreatedDate","CategoryID","Name","Layout","IsDynamicContent","Content","IsSurvey","IsBlank","Key" }; getContentArea.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestContentArea } }; getResponse = getContentArea.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); //Console.WriteLine("\n Info ContentArea"); //ET_ContentArea ContentAreaInfo = new ET_ContentArea(); //ContentAreaInfo.authStub = myclient; //InfoReturn info = ContentAreaInfo.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()); //} } }
public PostReturn(APIObject[] theObjects, ET_Client theClient) { this.Message = ""; this.Status = true; this.MoreResults = false; string OverallStatus = string.Empty, RequestID = string.Empty; Result[] requestResults = new Result[0]; theClient.refreshToken(); using (var scope = new OperationContextScope(theClient.soapclient.InnerChannel)) { //Add oAuth token to SOAP header. XNamespace ns = "http://exacttarget.com"; var oauthElement = new XElement(ns + "oAuthToken", theClient.internalAuthToken); var xmlHeader = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement); OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader); var httpRequest = new System.ServiceModel.Channels.HttpRequestMessageProperty(); OperationContext.Current.OutgoingMessageProperties.Add(System.ServiceModel.Channels.HttpRequestMessageProperty.Name, httpRequest); httpRequest.Headers.Add(HttpRequestHeader.UserAgent, theClient.SDKVersion); List<APIObject> lObjects = new List<APIObject>(); foreach (APIObject ao in theObjects) { lObjects.Add(this.TranslateObject(ao)); } requestResults = theClient.soapclient.Create(new CreateOptions(), lObjects.ToArray(), out RequestID, out OverallStatus); this.Status = true; this.Code = 200; this.MoreResults = false; this.Message = ""; if (OverallStatus != "OK") { this.Status = false; } if (requestResults.GetType() == typeof(CreateResult[]) && requestResults.Length > 0) { List<ResultDetail> results = new List<ResultDetail>(); foreach (CreateResult cr in requestResults) { ResultDetail detail = new ResultDetail(); if (cr.StatusCode != null) detail.StatusCode = cr.StatusCode; if (cr.StatusMessage != null) detail.StatusMessage = cr.StatusMessage; if (cr.NewObjectID != null) detail.NewObjectID = cr.NewObjectID; if (cr.Object != null) detail.Object = this.TranslateObject(cr.Object); detail.OrdinalID = cr.OrdinalID; detail.ErrorCode = cr.ErrorCode; detail.NewID = cr.NewID; results.Add(detail); } this.Results = results.ToArray(); } } }
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); }
public void RetrieveObjectsByFolderID(string folderId, ET_Client etClient, string path, string contentType) { // Create the SOAP binding for call. BasicHttpBinding binding = new BasicHttpBinding(); binding.Name = "UserNameSoapBinding"; binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; binding.MaxReceivedMessageSize = 2147483647; var client = new FuelSDK.SoapClient(binding, etClient.soapclient.Endpoint.Address); client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; using (var scope = new OperationContextScope(client.InnerChannel)) { // Add oAuth token to SOAP header. XNamespace ns = "http://exacttarget.com"; var oauthElement = new XElement(ns + "oAuthToken", etClient.internalAuthToken); var xmlHeader = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement); OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader); List<object> folders = new List<object>(); string cType = "Email"; switch (contentType) { case "media": cType = "Portfolio"; break; case "dataextension": cType = "DataExtension"; break; case "content": cType = "ContentArea"; break; } string requestID; // Filter by the Folder/Category SimpleFilterPart sfp = new SimpleFilterPart(); sfp.Property = "CategoryID"; sfp.SimpleOperator = SimpleOperators.equals; sfp.Value = new string[] { folderId }; // Create the RetrieveRequest object RetrieveRequest request = new RetrieveRequest(); request.ObjectType = cType; request.Filter = sfp; request.Properties = new string[] { "CustomerKey", "Name", "CreatedDate", "ModifiedDate" }; if(contentType == "media") request.Properties = new string[] { "CustomerKey", "FileName", "CreatedDate", "ModifiedDate" }; // Execute the Retrieve APIObject[] results; string status = client.Retrieve(request, out requestID, out results); for (int cntr = 0; cntr < results.Length; cntr++) { string sql = "INSERT INTO [Results] ([IdResult] ,[CustomerKey] ,[Name] ,[ResultType] ,[Path] ,[URL],[ThumbnailURL],[CreatedDate],[ModifiedDate],[IdContactIndex])VALUES (@IdResult ,@CustomerKey ,@Name ,@ResultType ,@Path ,@URL,@ThumbnailURL,@CreatedDate,@ModifiedDate,@IdContactIndex)"; switch (contentType) { case "media": var portfolio = (Portfolio)results[cntr]; using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["FindIt.Data.Entities"].ConnectionString)) using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, cn)) { cmd.Parameters.Add("@IdResult", System.Data.SqlDbType.UniqueIdentifier).Value = Guid.NewGuid(); cmd.Parameters.Add("@CustomerKey", System.Data.SqlDbType.VarChar).Value = portfolio.CustomerKey; cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value = portfolio.FileName; cmd.Parameters.Add("@ResultType", System.Data.SqlDbType.VarChar).Value = contentType; cmd.Parameters.Add("@Path", System.Data.SqlDbType.VarChar).Value = path; cmd.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@ThumbnailURL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@CreatedDate", System.Data.SqlDbType.DateTime).Value = portfolio.CreatedDate; cmd.Parameters.Add("@ModifiedDate", System.Data.SqlDbType.DateTime).Value = portfolio.ModifiedDate; cmd.Parameters.Add("@IdContactIndex", System.Data.SqlDbType.UniqueIdentifier).Value = new Guid("A08D166C-F310-4F2D-8D44-5DD8F1564B8F"); cn.Open(); cmd.ExecuteNonQuery(); } break; case "dataextension": var dataextension = (DataExtension)results[cntr]; using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["FindIt.Data.Entities"].ConnectionString)) using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, cn)) { cmd.Parameters.Add("@IdResult", System.Data.SqlDbType.UniqueIdentifier).Value = Guid.NewGuid(); cmd.Parameters.Add("@CustomerKey", System.Data.SqlDbType.VarChar).Value = dataextension.CustomerKey; cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value = dataextension.Name; cmd.Parameters.Add("@ResultType", System.Data.SqlDbType.VarChar).Value = contentType; cmd.Parameters.Add("@Path", System.Data.SqlDbType.VarChar).Value = path; cmd.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@ThumbnailURL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@CreatedDate", System.Data.SqlDbType.DateTime).Value = dataextension.CreatedDate; cmd.Parameters.Add("@ModifiedDate", System.Data.SqlDbType.DateTime).Value = dataextension.ModifiedDate; cmd.Parameters.Add("@IdContactIndex", System.Data.SqlDbType.UniqueIdentifier).Value = new Guid("A08D166C-F310-4F2D-8D44-5DD8F1564B8F"); cn.Open(); cmd.ExecuteNonQuery(); } break; case "content": var content = (ContentArea)results[cntr]; using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["FindIt.Data.Entities"].ConnectionString)) using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, cn)) { cmd.Parameters.Add("@IdResult", System.Data.SqlDbType.UniqueIdentifier).Value = Guid.NewGuid(); cmd.Parameters.Add("@CustomerKey", System.Data.SqlDbType.VarChar).Value = content.CustomerKey; cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value = content.Name; cmd.Parameters.Add("@ResultType", System.Data.SqlDbType.VarChar).Value = contentType; cmd.Parameters.Add("@Path", System.Data.SqlDbType.VarChar).Value = path; cmd.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@ThumbnailURL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@CreatedDate", System.Data.SqlDbType.DateTime).Value = content.CreatedDate; cmd.Parameters.Add("@ModifiedDate", System.Data.SqlDbType.DateTime).Value = content.ModifiedDate; cmd.Parameters.Add("@IdContactIndex", System.Data.SqlDbType.UniqueIdentifier).Value = new Guid("A08D166C-F310-4F2D-8D44-5DD8F1564B8F"); cn.Open(); cmd.ExecuteNonQuery(); } break; default: var email = (Email)results[cntr]; using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["FindIt.Data.Entities"].ConnectionString)) using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, cn)) { cmd.Parameters.Add("@IdResult",System.Data.SqlDbType.UniqueIdentifier).Value = Guid.NewGuid(); cmd.Parameters.Add("@CustomerKey", System.Data.SqlDbType.VarChar).Value = email.CustomerKey; cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value = email.Name; cmd.Parameters.Add("@ResultType", System.Data.SqlDbType.VarChar).Value = contentType; cmd.Parameters.Add("@Path", System.Data.SqlDbType.VarChar).Value = path; cmd.Parameters.Add("@URL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@ThumbnailURL", System.Data.SqlDbType.VarChar).Value = ""; cmd.Parameters.Add("@CreatedDate", System.Data.SqlDbType.DateTime).Value = email.CreatedDate; cmd.Parameters.Add("@ModifiedDate", System.Data.SqlDbType.DateTime).Value = email.ModifiedDate; cmd.Parameters.Add("@IdContactIndex", System.Data.SqlDbType.UniqueIdentifier).Value = new Guid("A08D166C-F310-4F2D-8D44-5DD8F1564B8F"); cn.Open(); cmd.ExecuteNonQuery(); } break; } } } }
static void TestET_Email(){ ET_Client myclient = new ET_Client(); string NameOfTestEmail = "CSharpSDKEmail"; Console.WriteLine("--- Testing Email ---"); Console.WriteLine("\n Retrieve All Email with GetMoreResults"); ET_Email getAllEmail = new ET_Email(); getAllEmail.AuthStub = myclient; getAllEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" }; GetReturn grAllEmail = getAllEmail.Get(); Console.WriteLine("Get Status: " + grAllEmail.Status.ToString()); Console.WriteLine("Message: " + grAllEmail.Message.ToString()); Console.WriteLine("Code: " + grAllEmail.Code.ToString()); Console.WriteLine("Results Length: " + grAllEmail.Results.Length); while (grAllEmail.MoreResults) { Console.WriteLine("\n Continue Retrieve All Email with GetMoreResults"); grAllEmail = getAllEmail.GetMoreResults(); Console.WriteLine("Get Status: " + grAllEmail.Status.ToString()); Console.WriteLine("Message: " + grAllEmail.Message.ToString()); Console.WriteLine("Code: " + grAllEmail.Code.ToString()); Console.WriteLine("Results Length: " + grAllEmail.Results.Length); } Console.WriteLine("\n Create Email"); ET_Email postEmail = new ET_Email(); postEmail.AuthStub = myclient; postEmail.Name = NameOfTestEmail; postEmail.CustomerKey = NameOfTestEmail; postEmail.Subject = "Created Using the Fuel SDK"; postEmail.HTMLBody = "<b>Some HTML Goes here</b>"; PostReturn postResponse = postEmail.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 Retrieve newly create Email"); ET_Email getEmail = new ET_Email(); getEmail.AuthStub = myclient; getEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","HTMLBody","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" }; getEmail.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestEmail } }; GetReturn getResponse = getEmail.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_Email ResultEmail in getResponse.Results) { Console.WriteLine("--ID: " + ResultEmail.ID + ", Name: " + ResultEmail.Name + ", HTMLBody: " + ResultEmail.HTMLBody); } Console.WriteLine("\n Update Email"); ET_Email patchEmail = new ET_Email(); patchEmail.CustomerKey = NameOfTestEmail; patchEmail.HTMLBody = "<b>Some HTML Goes here. NOW WITH NEW CONTENT</b>"; patchEmail.AuthStub = myclient; FuelSDK.PatchReturn patchFR = patchEmail.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 updated Email"); getEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","HTMLBody","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" }; getEmail.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestEmail } }; getResponse = getEmail.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_Email ResultEmail in getResponse.Results) { Console.WriteLine("--ID: " + ResultEmail.ID + ", Name: " + ResultEmail.Name + ", HTMLBody: " + ResultEmail.HTMLBody); } Console.WriteLine("\n Delete Email"); ET_Email delEmail = new ET_Email(); delEmail.CustomerKey = NameOfTestEmail; delEmail.AuthStub = myclient; DeleteReturn deleteResponse = delEmail.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 Email to confirm deletion"); getEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","HTMLBody","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" }; getEmail.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestEmail } }; getResponse = getEmail.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); Console.WriteLine("\n Info Email"); ET_Email EmailInfo = new ET_Email(); EmailInfo.AuthStub = myclient; InfoReturn info = EmailInfo.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_Campaign() { ET_Client myclient = new ET_Client(); string IDOfpostCampaign = string.Empty; string IDOfpostCampaignAsset = string.Empty; string ExampleAssetType = "LIST"; string ExampleAssetItemID = "1953114"; Console.WriteLine("--- Testing Campaign ---"); Console.WriteLine("\n Retrieve All Campaigns"); ET_Campaign getCampaign = new ET_Campaign(); getCampaign.AuthStub = myclient; GetReturn grCampaign = getCampaign.Get(); Console.WriteLine("Get Status: " + grCampaign.Status.ToString()); Console.WriteLine("Message: " + grCampaign.Message.ToString()); Console.WriteLine("Code: " + grCampaign.Code.ToString()); Console.WriteLine("Results Length: " + grCampaign.Results.Length); Console.WriteLine("MoreResults: " + grCampaign.MoreResults.ToString()); foreach (ET_Campaign thisCamp in grCampaign.Results) { Console.WriteLine("Name: " + thisCamp.Name + ", ID: " + thisCamp.ID + ", Description: " + thisCamp.Description); } if (grCampaign.MoreResults) { grCampaign = getCampaign.GetMoreResults(); Console.WriteLine("Get Status: " + grCampaign.Status.ToString()); Console.WriteLine("Message: " + grCampaign.Message.ToString()); Console.WriteLine("Code: " + grCampaign.Code.ToString()); Console.WriteLine("Results Length: " + grCampaign.Results.Length); Console.WriteLine("MoreResults: " + grCampaign.MoreResults.ToString()); foreach (ET_Campaign thisCamp in grCampaign.Results) { Console.WriteLine("Name: " + thisCamp.Name + ", ID: " + thisCamp.ID + ", Description: " + thisCamp.Description); } } Console.WriteLine("\n Create Campaign"); ET_Campaign camp = new ET_Campaign(); camp.AuthStub = myclient; camp.Name = "CSharpSDKCreatedForTEST"; camp.Description = "CSharpSDKCreatedForTEST"; PostReturn prCampaign = camp.Post(); Console.WriteLine("Post Status: " + prCampaign.Status.ToString()); Console.WriteLine("Message: " + prCampaign.Message.ToString()); Console.WriteLine("Code: " + prCampaign.Code.ToString()); Console.WriteLine("Results Length: " + prCampaign.Results.Length); if (prCampaign.Results.Length > 0) { ET_Campaign campaign = (ET_Campaign)prCampaign.Results[0].Object; Console.WriteLine("--ID: " + campaign.ID + ", CreatedDate: " + campaign.CreatedDate); IDOfpostCampaign = campaign.ID.ToString(); Console.WriteLine("\n Retrieve the new Campaign"); ET_Campaign singleCampaign = new ET_Campaign(); singleCampaign.AuthStub = myclient; singleCampaign.ID = campaign.ID; GetReturn grSingleCamp = singleCampaign.Get(); Console.WriteLine("Get Status: " + grSingleCamp.Status.ToString()); Console.WriteLine("Message: " + grSingleCamp.Message.ToString()); Console.WriteLine("Code: " + grSingleCamp.Code.ToString()); Console.WriteLine("Results Length: " + grSingleCamp.Results.Length); Console.WriteLine("\n Create a new Campaign Asset"); ET_CampaignAsset postCampAsset = new ET_CampaignAsset(); postCampAsset.AuthStub = myclient; postCampAsset.CampaignID = IDOfpostCampaign; postCampAsset.Type = ExampleAssetType; postCampAsset.IDs = new string[] { ExampleAssetItemID }; PostReturn prCampAsset = postCampAsset.Post(); Console.WriteLine("Post Status: " + prCampAsset.Status.ToString()); Console.WriteLine("Message: " + prCampAsset.Message.ToString()); Console.WriteLine("Code: " + prCampAsset.Code.ToString()); Console.WriteLine("Results Length: " + prCampAsset.Results.Length); if (prCampAsset.Status) { IDOfpostCampaignAsset = prCampAsset.Results[0].Object.ID.ToString(); Console.WriteLine("\n Retrieve a single new Campaign Asset"); ET_CampaignAsset singleCampAsset = new ET_CampaignAsset(); singleCampAsset.AuthStub = myclient; singleCampAsset.ID = Convert.ToInt16(IDOfpostCampaignAsset); singleCampAsset.CampaignID = IDOfpostCampaign; GetReturn grSingleCampAsset = singleCampAsset.Get(); Console.WriteLine("Get Status: " + grSingleCampAsset.Status.ToString()); Console.WriteLine("Message: " + grSingleCampAsset.Message.ToString()); Console.WriteLine("Code: " + grSingleCampAsset.Code.ToString()); Console.WriteLine("Results Length: " + grSingleCampAsset.Results.Length); Console.WriteLine("\n Delete the new Campaign Asset"); ET_CampaignAsset deleteCampAsset = new ET_CampaignAsset(); deleteCampAsset.AuthStub = myclient; deleteCampAsset.ID = Convert.ToInt16(IDOfpostCampaignAsset); deleteCampAsset.CampaignID = IDOfpostCampaign; DeleteReturn drSingleCampAsset = deleteCampAsset.Delete(); Console.WriteLine("Get Status: " + drSingleCampAsset.Status.ToString()); Console.WriteLine("Message: " + drSingleCampAsset.Message.ToString()); Console.WriteLine("Code: " + drSingleCampAsset.Code.ToString()); Console.WriteLine("Results Length: " + drSingleCampAsset.Results.Length); } Console.WriteLine("\n Delete Campaign"); ET_Campaign delCampaign = new ET_Campaign(); delCampaign.AuthStub = myclient; delCampaign.ID = campaign.ID; DeleteReturn drCampaign = delCampaign.Delete(); Console.WriteLine("Delete Status: " + drCampaign.Status.ToString()); Console.WriteLine("Message: " + drCampaign.Message.ToString()); Console.WriteLine("Code: " + drCampaign.Code.ToString()); Console.WriteLine("Results Length: " + drCampaign.Results.Length); } }
public void Execute(IJobExecutionContext context) { try { HelperDatabase conexionBD = new HelperDatabase("putyoursqlormysqlserverhere", "putyourdbnamehere", "user", "password", (int)HelperDatabase.typeConn.MYSQL,3306); conexionBD.Connect(); var objResult = conexionBD.Execute("SELECT Value from Configuration where Name='LastPollTime'"); conexionBD.Disconnect(); if (objResult.error != null) { Console.WriteLine("Error retrieving last poll timestamp."); } DateTime lastPollTimeStamp =DateTime.Parse (objResult.rows[0][0].ToString()); ET_Client client = new ET_Client(); Console.WriteLine("Establishing Connection..."); ET_Send sendObject=new ET_Send(); sendObject.AuthStub = client; sendObject.SearchFilter = new SimpleFilterPart() { Property = "SendDate", SimpleOperator = SimpleOperators.greaterThan, DateValue = new DateTime[] { lastPollTimeStamp } }; //sendObject.Props = new string[] { "ID", "PartnerKey", "CreatedDate", "ModifiedDate", "Client.ID", "Client.PartnerClientKey", "Email.ID", "Email.PartnerKey", "SendDate", "FromAddress", "FromName", "Duplicates", "InvalidAddresses", "ExistingUndeliverables", "ExistingUnsubscribes", "HardBounces", "SoftBounces", "OtherBounces", "ForwardedEmails", "UniqueClicks", "UniqueOpens", "NumberSent", "NumberDelivered", "NumberTargeted", "NumberErrored", "NumberExcluded", "Unsubscribes", "MissingAddresses", "Subject", "PreviewURL", "SentDate", "EmailName", "Status", "IsMultipart", "SendLimit", "SendWindowOpen", "SendWindowClose", "IsAlwaysOn", "Additional", "BCCEmail", "EmailSendDefinition.ObjectID", "EmailSendDefinition.CustomerKey" }; GetReturn response = sendObject.Get(); Console.WriteLine("---Results obtained---"); foreach (ET_Send send in response.Results) { conexionBD.Connect(); var insertNewSendRecord = conexionBD.Execute("INSERT INTO SentData "); conexionBD.Disconnect(); if (objResult.error != null){ Console.WriteLine("Error updating last poll timestamp."); } string subject = send.Subject; string status = send.Status; if (!subject.StartsWith("Test Send") && status.Equals("Complete")){ string previewUrl = send.PreviewURL; string domain = send.FromAddress; string templateName = send.EmailName; DateTime sentDate = send.SendDate; int targetedNumber = send.NumberTargeted; int uniqueClicks = send.UniqueClicks; string fromAdress = send.FromAddress; string fromName = send.FromName; conexionBD.Connect(); var insertStatement = String.Format("INSERT INTO SentData(Url,Domain,Date,Subject,Template_Name) values ('{0}','{1}','{2}','{3}','{4}')", previewUrl, domain, sentDate.ToString("yyyy-MM-dd HH:mm:ss"), subject.Trim(), templateName); var updatePollTimeResult = conexionBD.Execute(insertStatement); conexionBD.Disconnect(); if (updatePollTimeResult.error != null) { Console.WriteLine("Error updating last poll timestamp."); } } } } catch (Exception ConnectionException){ Console.WriteLine("Failed to do polling Job."); Console.WriteLine(ConnectionException.Message); } }
private string GetEmailName(ET_Client client, int sendID) { if (!_names.ContainsKey(sendID)) { ET_Send send = new ET_Send(); send.AuthStub = client; send.Props = new string[] { "ID", "EmailName", }; send.SearchFilter = new SimpleFilterPart() { Property = "ID", SimpleOperator = SimpleOperators.equals, Value = new string[] { Convert.ToString(sendID) }, }; GetReturn results = send.Get(); if (results.Results.Length > 0) { ET_Send item = (ET_Send)results.Results[0]; _names[sendID] = item.EmailName.Trim(); } } return _names[sendID]; }
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_List() { ET_Client myclient = new ET_Client(); Console.WriteLine("--- Testing List ---"); int MyNewListID = 0; Console.WriteLine("\n Create List"); ET_List list = new ET_List(); list.AuthStub = myclient; list.ListName = "C# SDK Rules!!"; list.Description = "This is my SDK Created List"; PostReturn postFR = list.Post(); Console.WriteLine("Post Status: " + postFR.Status.ToString()); Console.WriteLine("Message: " + postFR.Message.ToString()); Console.WriteLine("Code: " + postFR.Code.ToString()); Console.WriteLine("Results Length: " + postFR.Results.Length); if (postFR.Results.Length > 0) { MyNewListID = postFR.Results[0].NewID; } if (MyNewListID > 0) { Console.WriteLine("\n Retrieve newly create list"); list.Props = new string[] { "ID", "ListName", "Description" }; list.SearchFilter = new SimpleFilterPart() { Property = "ID", SimpleOperator = SimpleOperators.equals, Value = new String[] { MyNewListID.ToString() } }; GetReturn getFR = list.Get(); Console.WriteLine("Get Status: " + getFR.Status.ToString()); Console.WriteLine("Message: " + getFR.Message.ToString()); Console.WriteLine("Code: " + getFR.Code.ToString()); Console.WriteLine("Results Length: " + getFR.Results.Length); foreach (ET_List ResultList in getFR.Results) { Console.WriteLine("--ID: " + ResultList.ID + ", Name: " + ResultList.ListName + ", Description: " + ResultList.Description); } Console.WriteLine("\n Update list"); ET_List patchList = new ET_List(); patchList.ID = MyNewListID; patchList.Description = "This is the new description"; patchList.AuthStub = myclient; FuelSDK.PatchReturn patchFR = patchList.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 List that should have description updated"); list.Props = new string[] { "ID", "ListName", "Description" }; list.SearchFilter = new SimpleFilterPart() { Property = "ID", SimpleOperator = SimpleOperators.equals, Value = new String[] { MyNewListID.ToString() } }; getFR = list.Get(); Console.WriteLine("Get Status: " + getFR.Status.ToString()); Console.WriteLine("Message: " + getFR.Message.ToString()); Console.WriteLine("Code: " + getFR.Code.ToString()); Console.WriteLine("Results Length: " + getFR.Results.Length); foreach (ET_List ResultList in getFR.Results) { Console.WriteLine("--ID: " + ResultList.ID + ", Name: " + ResultList.ListName + ", Description: " + ResultList.Description); } Console.WriteLine("\n Delete List"); ET_List delList = new ET_List(); delList.ID = MyNewListID; delList.AuthStub = myclient; FuelSDK.DeleteReturn fr = delList.Delete(); Console.WriteLine("Delete Status: " + fr.Status.ToString()); Console.WriteLine("Message: " + fr.Message.ToString()); Console.WriteLine("Code: " + fr.Code.ToString()); Console.WriteLine("Results Length: " + fr.Results.Length); Console.WriteLine("\n Retrieve List to confirm deletion"); list.Props = new string[] { "ID", "ListName", "Description" }; list.SearchFilter = new SimpleFilterPart() { Property = "ID", SimpleOperator = SimpleOperators.equals, Value = new String[] { MyNewListID.ToString() } }; getFR = list.Get(); Console.WriteLine("Get Status: " + getFR.Status.ToString()); Console.WriteLine("Message: " + getFR.Message.ToString()); Console.WriteLine("Code: " + getFR.Code.ToString()); Console.WriteLine("Results Length: " + getFR.Results.Length); foreach (ET_List ResultList in getFR.Results) { Console.WriteLine("--ID: " + ResultList.ID + ", Name: " + ResultList.ListName + ", Description: " + ResultList.Description); } Console.WriteLine("\n Info List"); ET_List listInfo = new ET_List(); listInfo.AuthStub = myclient; InfoReturn info = listInfo.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_SentEvent() { DateTime filterDate = new DateTime(2013, 1, 15, 13, 0, 0); Console.WriteLine("--- Testing SentEvent ---"); ET_Client myclient = new ET_Client(); Console.WriteLine("Retrieve Filtered SentEvents with GetMoreResults"); ET_SentEvent oe = new ET_SentEvent(); oe.AuthStub = myclient; oe.SearchFilter = new SimpleFilterPart() { Property = "EventDate", SimpleOperator = SimpleOperators.greaterThan, DateValue = new DateTime[] { filterDate } }; oe.Props = new string[] { "SendID", "SubscriberKey", "EventDate", "Client.ID", "EventType", "BatchID", "TriggeredSendDefinitionObjectID", "PartnerKey" }; 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_SentEvent SentEvent in oeGet.Results) //{ // Console.WriteLine("SubscriberKey: " + SentEvent.SubscriberKey + ", EventDate: " + SentEvent.EventDate.ToString()); //} while (oeGet.MoreResults) { Console.WriteLine("Continue Retrieve Filtered SentEvents 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 SentEvents with GetMoreResults"); //ET_SentEvent oe = new ET_SentEvent(); //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_SentEvent SentEvent in oeGet.Results) ////{ //// Console.WriteLine("SubscriberKey: " + SentEvent.SubscriberKey + ", EventDate: " + SentEvent.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()); //} }
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()); } } }