Beispiel #1
0
        public PostReturnStatus CreateDataExtension(string name, string customerKey, string primaryColumnName)
        {
            ET_DataExtension postDataExtension = new ET_DataExtension();

            postDataExtension.AuthStub    = _etClient;
            postDataExtension.Name        = name;
            postDataExtension.CustomerKey = customerKey;
            ET_DataExtensionColumn nameColumn = new ET_DataExtensionColumn()
            {
                Name = primaryColumnName, FieldType = DataExtensionFieldType.Text, IsPrimaryKey = true, MaxLength = 100, IsRequired = true
            };

            postDataExtension.Columns = new ET_DataExtensionColumn[] { nameColumn };
            PostReturn postResponse = postDataExtension.Post();

            PostReturnStatus status = new PostReturnStatus()
            {
                Status        = postResponse.Status.ToString(),
                Message       = postResponse.Message.ToString(),
                Code          = postResponse.Code.ToString(),
                ResultsLength = postResponse.Results.Length
            };

            return(status);
        }
Beispiel #2
0
        public APIObject[] RetrieveAllDataExtensions()
        {
            List <GetReturnStatus> statusList = new List <GetReturnStatus>();

            //Get all of the DataExtensions in an Account
            ET_DataExtension getAllDataExtension = new ET_DataExtension();

            getAllDataExtension.AuthStub = _etClient;
            getAllDataExtension.Props    = new string[] { "CustomerKey", "Name" };
            GetReturn grAllDataExtension = getAllDataExtension.Get();


            return(grAllDataExtension.Results);
        }
Beispiel #3
0
        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_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 Test_CreateDataExtensions()
        {
            var myclient = new ET_Client();

            Console.WriteLine("--- Testing CreateDataExtensions ---");

            var deOne = new ET_DataExtension
            {
                Name        = "HelperDEOne",
                CustomerKey = "HelperDEOne",
                Columns     = new[] {
                    new ET_DataExtensionColumn {
                        Name = "Name", FieldType = DataExtensionFieldType.Text, IsPrimaryKey = true, MaxLength = 100, IsRequired = true
                    },
                    new ET_DataExtensionColumn {
                        Name = "OtherField", FieldType = DataExtensionFieldType.Text
                    }
                },
            };

            var deTwo = new ET_DataExtension
            {
                Name        = "HelperDETwo",
                CustomerKey = "HelperDETwo",
                Columns     = new[] {
                    new ET_DataExtensionColumn {
                        Name = "Name", FieldType = DataExtensionFieldType.Text, IsPrimaryKey = true, MaxLength = 100, IsRequired = true
                    },
                    new ET_DataExtensionColumn {
                        Name = "OtherField", FieldType = DataExtensionFieldType.Text
                    }
                },
            };

            var aCoupleDEs = new[] { deOne, deTwo };

            var createReturn = myclient.CreateDataExtensions(aCoupleDEs);

            Console.WriteLine("Helper Status: " + createReturn.Status.ToString());
            Console.WriteLine("Message: " + createReturn.Message);
            Console.WriteLine("Code: " + createReturn.Code.ToString());

            if (createReturn.Status)
            {
                Console.WriteLine("\n Delete DEOne");
                var delDataExtension = new ET_DataExtension
                {
                    CustomerKey = "HelperDEOne",
                    AuthStub    = myclient,
                };
                var deleteResponse = delDataExtension.Delete();
                Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString());
                Console.WriteLine("Message: " + deleteResponse.Message);
                Console.WriteLine("Code: " + deleteResponse.Code.ToString());
                Console.WriteLine("Results Length: " + deleteResponse.Results.Length);

                Console.WriteLine("\n Delete DETwo");
                var delDataExtension2 = new ET_DataExtension
                {
                    CustomerKey = "HelperDETwo",
                    AuthStub    = myclient,
                };
                var deleteResponse2 = delDataExtension2.Delete();
                Console.WriteLine("Delete Status: " + deleteResponse2.Status.ToString());
                Console.WriteLine("Message: " + deleteResponse2.Message);
                Console.WriteLine("Code: " + deleteResponse2.Code.ToString());
                Console.WriteLine("Results Length: " + deleteResponse2.Results.Length);
            }
        }
        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);
            }
        }