This page contains information about creating a subscriber attribute.
Why Create a Subscriber Attribute
Subscriber attributes contain specific information about your subscribers, such as first and last name, gender, and geographical location. You can assign specific information as part of a subscriber attribute to be used as part of sends or subscriber management. Use the information to better target your sends and include only the subscribers you wish in certain groups. For example, you can create a subscriber attribute called Sales Region, assign subscribers to those regions, then conduct sends to specific groups instead of all subscribers.
How To Create a Subscriber Attribute
Use the sample code below as models for your own API calls. The number of subscriber attributes that can be created on an account is defined during account configuration. More subscriber attributes can’t be added to an account without re-configuring the number available for the account. Contact your Account Executive for more information about changing the number of subscriber attributes available on your account.
Sample .NET Code
1using System;2using System.Configuration;3using System.Data;4using System.Web;5using etAPI;6public partial class SubscriberAttributeCreate : System.Web.UI.Page7{8 //Global Variables9 private SoapClient client = new SoapClient();10 protected void btnSubmit_Click(object sender, EventArgs e)11 {12 try13 {14 //Create Subscriber object [Subscribers > My Subscribers > Profile Management]15 PropertyDefinition pd = new PropertyDefinition();16 pd.Name = "FromAPI";17 pd.PropertyType = PropertyType.@string;18 pd.PropertyTypeSpecified = true;19 pd.IsEditable = true;20 pd.IsEditableSpecified = true;21 try22 {23 string status = String.Empty;24 string statusMess = String.Empty;25 string requestID = String.Empty;26 //Call the Create method on the PropertyDefinition object27 ConfigureResult[] results = null;28 results = client.Configure(null, "create", new APIObject[] { pd }, out status, out statusMess, out requestID);29 //Display Results30 lblMessage.Text += "Overall Status: " + status;31 lblMessage.Text += "<br />";32 lblMessage.Text += "Number of Results: " + results.Length;33 lblMessage.Text += "<br />";34 //Loop through each object returned and display the StatusMessage35 foreach (ConfigureResult cr in results)36 {37 lblMessage.Text += "Status Message: " + cr.StatusMessage;38 lblMessage.Text += "<br />";39 }40 }41 catch (Exception exCreate)42 {43 //Set Message44 lblMessage.Text += "<br /><br />CREATE ERROR:<br />" + exCreate.Message;45 }46 }47 catch (Exception exc)48 {49 //Set Message50 lblMessage.Text += "<br /><br />###ERROR<br />" + exc.Message;51 }52 }53}
Sample Code for Creating a Subscriber Attribute
1PropertyDefinition propDef = new PropertyDefinition();2propDef.Name = "CollegeName";3propDef.PropertyType = PropertyType.@string;4propDef.PropertyTypeSpecified = true;5propDef.IsEditable = true;6propDef.IsEditableSpecified = true;7// Call the Configure command with the Action "create"8ConfigureResult[] results = exacttarget.Configure(null, "create", new APIObject[] { propDef }, out status, out message, out requestID);9// Output the results10Console.WriteLine(status);11Console.WriteLine(message);12Console.WriteLine(results[0].ErrorCode);13Console.WriteLine(results[0].StatusCode);14Console.WriteLine(results[0].StatusMessage);15Console.WriteLine(results[0].Object.ID); // id of the attribute
Sample PropertyDefinition for a Subscriber Attribute with Restricted Values
1PropertyDefinition propDef = new PropertyDefinition();2propDef.Name = "MaxEducation";3propDef.PropertyType = PropertyType.@string;4propDef.PropertyTypeSpecified = true; // .NET only5propDef.IsRestrictedPicklist = true;6propDef.IsRestrictedPicklistSpecified = true; // .NET only7propDef.PicklistItems = new PicklistItem[3];8propDef.PicklistItems[0] = new PicklistItem();9propDef.PicklistItems[0].Value = "High School"; // default value10propDef.PicklistItems[0].IsDefaultValue = true;11propDef.PicklistItems[0].IsDefaultValueSpecified = true; // .NET only12propDef.PicklistItems[1] = new PicklistItem();13propDef.PicklistItems[1].Value = "Bachelors";14propDef.PicklistItems[2] = new PicklistItem();15propDef.PicklistItems[2].Value = "Masters";
Sample Code for Deleting a Subscriber Attribute
1PropertyDefinition propDef = new PropertyDefinition();2propDef.ID = 1234;3propDef.IDSpecified = true; //.NET only4// Call the Configure command with the Action "delete"5ConfigureResult[] results = integrationFramework.Configure(null, "delete", new APIObject[] { propDef }, out status, out message, out requestID);6// Output the results7Console.WriteLine(status); // OK, Error, or Has Error
Sample Java Code (Axis 1.4)
The sample code below demonstrates how to create attributes for On Your Behalf and Lock and Publish accounts.
1public void testCreateAttributeForSubscriber() throws RemoteException {2 AccountTestCase accountTestCase = new AccountTestCase();3 Account account = accountTestCase.retrieveAccountByPartnerKey();4 Soap stub = init();5 ConfigureRequestMsg configureRequestMsg = new ConfigureRequestMsg();6 PropertyDefinition definition = new PropertyDefinition();7 //create special Attribute under profile management, this attribute does not hold html content8 definition.setName("HTML__html");9 definition.setPropertyType(PropertyType.value1);10 //Set ClientID to create attribute on sub-account11 ConfigureOptions options = new ConfigureOptions();12 ClientID clientID = new ClientID();13 clientID.setPartnerClientKey(account.getPartnerKey());14 options.setClient(clientID); //this creates attribute in sub-account15 //definition.setClient(clientID); //this creates attribute in parent-account16 configureRequestMsg.setOptions(options);17 configureRequestMsg.setAction("Create");18 APIObject[] objects = {definition};19 configureRequestMsg.setConfigurations(objects);20 //API call to create to Attribute....21 ConfigureResponseMsg responseMsg = stub.configure(configureRequestMsg);22 assertNotNull(responseMsg.getOverallStatusMessage());23}
Sample Java Code (CXF)
The code below creates a new attribute for subscribers:
1// Creates new attributes2 public void testCreateAttributeForSubscriber() throws RemoteException {3try {4 Soap stub = init();56 PropertyDefinition definition = new PropertyDefinition();7 //create special Attribute under profile management, this attribute holds html content8 definition.setName("API_CREATED");9 definition.setPropertyType(PropertyType.STRING);101112 //Set ClientID to create attribute on sub-account13 ConfigureOptions options = new ConfigureOptions();14 //ClientID clientID = new ClientID();15 //clientID.setPartnerClientKey(account.getCustomerKey());16 //options.setClient(clientID); //this creates attribute in sub-account17 //definition.setClient(clientID); //this creates attribute in parent-account18 ConfigureRequestMsg.Configurations configuration = new ConfigureRequestMsg.Configurations();19 configuration.getConfiguration().addAll(Arrays.asList(definition));2021 ConfigureRequestMsg configureRequestMsg = new ConfigureRequestMsg();22 configureRequestMsg.setOptions(options);23 configureRequestMsg.setAction("Create");24 configureRequestMsg.setConfigurations(configuration);25 //API call to create to Attribute....26 ConfigureResponseMsg responseMsg = stub.configure(configureRequestMsg);27 assertNotNull(responseMsg.getOverallStatusMessage());2829 } catch (Exception e) {30 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.3132 }33 }