Пример #1
0
        public Response AddColumns(DataExtensionHead dataExtensionHead)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                var dataExtensionBase = new ET_DataExtension
                {
                    AuthStub = conexion.ETCliente,
                    Name = dataExtensionHead.Nombre,
                    CustomerKey = dataExtensionHead.Nombre
                };

                List<ET_DataExtensionColumn> fields = new List<ET_DataExtensionColumn>();

                foreach (var detalle in dataExtensionHead.DataExtensionDetalleList)
                {
                    //Create the field
                    ET_DataExtensionColumn field = new ET_DataExtensionColumn();
                    field.Name = detalle.Campo;
                    field.FieldType = GetTypeDataExtension(detalle.Tipo);
                    field.FieldTypeSpecified = true;
                    field.IsRequired = !detalle.EsNulo;
                    field.IsRequiredSpecified = !detalle.EsNulo;
                    field.IsPrimaryKey = detalle.EsClavePrimaria;
                    field.IsPrimaryKeySpecified = detalle.EsClavePrimaria;
                    if (field.IsPrimaryKey || detalle.Tamanio > 0)
                    {
                        field.MaxLength = detalle.Tamanio;
                        field.MaxLengthSpecified = true;
                    }
                    fields.Add(field);
                }

                dataExtensionBase.Columns = fields.ToArray();

                try
                {
                    var patchResponse = dataExtensionBase.Patch();
                    response.Success = patchResponse.Status;
                    response.Message = patchResponse.Message;
                    response.Code = patchResponse.Code;
                    response.Data = patchResponse.Results;
                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
        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);
            }
        }
Пример #3
0
        public Response DeleteByDataExtensionName(string dataExtensionName)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                ET_DataExtension dataextension = new ET_DataExtension();
                dataextension.AuthStub = conexion.ETCliente;
                dataextension.Name = dataExtensionName;

                try
                {
                    var delResponse = dataextension.Delete();
                    response.Success = delResponse.Status;
                    response.Message = delResponse.Message;
                    response.Code = delResponse.Code;
                    response.Data = delResponse.Results;
                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
Пример #4
0
        public Response Create(DataExtensionHead dataExtensionHead)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                var dataExtensionBase = new ET_DataExtension
                {
                    AuthStub = conexion.ETCliente,
                    Name = dataExtensionHead.Nombre,
                    CustomerKey = dataExtensionHead.Nombre,
                    Description = dataExtensionHead.Descripcion,
                    IsSendable = dataExtensionHead.EsUsadaComoBase,
                    IsSendableSpecified = dataExtensionHead.EsUsadaComoBase
                };

                if (dataExtensionHead.EsUsadaComoBase)
                {
                    //Is this data base table going to house Subscribers?
                    //de.IsSendable = true;
                    //de.IsSendableSpecified = true;
                    dataExtensionBase.IsSendable = dataExtensionHead.EsUsadaComoBase;
                    dataExtensionBase.IsSendableSpecified = dataExtensionHead.EsUsadaComoBase;

                    //The Name of the Column in the DE to map to ET
                    dataExtensionBase.SendableDataExtensionField = new DataExtensionField();
                    dataExtensionBase.SendableDataExtensionField.FieldType = DataExtensionFieldType.Text;
                    dataExtensionBase.SendableDataExtensionField.Name = dataExtensionHead.NombreBaseFuente;
                    //The Name of the Attribute in ET to Send to
                    dataExtensionBase.SendableSubscriberField = new FuelSDK.Attribute();
                    dataExtensionBase.SendableSubscriberField.Name = dataExtensionHead.NombreBaseMostrar;//If Subscriber Key is turned on this must be Subscriber Key
                }

                List<ET_DataExtensionColumn> fields = new List<ET_DataExtensionColumn>();

                foreach (var detalle in dataExtensionHead.DataExtensionDetalleList)
                {
                    //Create the field
                    ET_DataExtensionColumn field = new ET_DataExtensionColumn();
                    field.Name = detalle.Campo;
                    field.FieldType = GetTypeDataExtension(detalle.Tipo);
                    field.FieldTypeSpecified = true;
                    field.IsRequired = !detalle.EsNulo;
                    field.IsRequiredSpecified = !detalle.EsNulo;
                    field.IsPrimaryKey = detalle.EsClavePrimaria;
                    field.IsPrimaryKeySpecified = detalle.EsClavePrimaria;
                    if (field.IsPrimaryKey || detalle.Tamanio > 0)
                    {
                        field.MaxLength = detalle.Tamanio;
                        field.MaxLengthSpecified = true;
                    }
                    fields.Add(field);
                }

                dataExtensionBase.Columns = fields.ToArray();

                try
                {
                    var postResponse = dataExtensionBase.Post();
                    response.Success = postResponse.Status;
                    response.Message = postResponse.Message;
                    response.Code = postResponse.Code;
                    response.Data = postResponse.Results;
                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
        private void GetDataExtensionName()
        {
            if (this.DataExtensionName == null)
            {
                if (this.DataExtensionCustomerKey != null)
                {
                    ET_DataExtension lookupDE = new ET_DataExtension();
                    lookupDE.AuthStub = this.AuthStub;
                    lookupDE.Props = new string[] { "Name", "CustomerKey" };
                    lookupDE.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new string[] { this.DataExtensionCustomerKey } };
                    GetReturn grDEName = lookupDE.Get();

                    if (grDEName.Status && grDEName.Results.Length > 0)
                    {
                        this.DataExtensionName = ((ET_DataExtension)grDEName.Results[0]).Name;
                    }
                    else
                    {
                        throw new Exception("Unable to process ET_DataExtensionRow request due to unable to find DataExtension based on CustomerKey");
                    }
                }
                else
                {
                    throw new Exception("Unable to process ET_DataExtensionRow request due to DataExtensionCustomerKey or DataExtensionName not being defined on ET_DatExtensionRow");
                }
            }
        }
        public FuelReturn CreateDataExtensions(ET_DataExtension[] ArrayOfET_DataExtension)
        {
            List<ET_DataExtension> cleanedArray = new List<ET_DataExtension>();

            foreach (ET_DataExtension de in ArrayOfET_DataExtension)
            {
                de.Fields = de.Columns;
                de.Columns = null;
                cleanedArray.Add(de);
            }
            return new PostReturn(cleanedArray.ToArray(), this);
        }
Пример #7
0
        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());
                }
            }
        }