Create a Subscriber Attribute

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.Page
7{
8    //Global Variables
9    private SoapClient client = new SoapClient();
10    protected void btnSubmit_Click(object sender, EventArgs e)
11    {
12        try
13        {
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            try
22            {
23                string status = String.Empty;
24                string statusMess = String.Empty;
25                string requestID = String.Empty;
26                //Call the Create method on the PropertyDefinition object
27                ConfigureResult[] results = null;
28                results = client.Configure(null, "create", new APIObject[] { pd }, out status, out statusMess, out requestID);
29                //Display Results
30                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 StatusMessage
35                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 Message
44                lblMessage.Text += "<br /><br />CREATE ERROR:<br />" + exCreate.Message;
45            }
46        }
47        catch (Exception exc)
48        {
49            //Set Message
50            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 results
10Console.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 only
5propDef.IsRestrictedPicklist = true;
6propDef.IsRestrictedPicklistSpecified = true; // .NET only
7propDef.PicklistItems = new PicklistItem[3];
8propDef.PicklistItems[0] = new PicklistItem();
9propDef.PicklistItems[0].Value = "High School"; // default value
10propDef.PicklistItems[0].IsDefaultValue = true;
11propDef.PicklistItems[0].IsDefaultValueSpecified = true; // .NET only
12propDef.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 only
4// 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 results
7Console.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 content
8        definition.setName("HTML__html");
9        definition.setPropertyType(PropertyType.value1);
10        //Set ClientID to create attribute on sub-account
11        ConfigureOptions options = new ConfigureOptions();
12        ClientID clientID = new ClientID();
13        clientID.setPartnerClientKey(account.getPartnerKey());
14        options.setClient(clientID);  //this creates attribute in sub-account
15        //definition.setClient(clientID); //this creates attribute in parent-account
16        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 attributes
2        public void testCreateAttributeForSubscriber() throws RemoteException {
3try {
4            Soap stub = init();
5
6              PropertyDefinition definition = new PropertyDefinition();
7              //create special Attribute under profile management, this attribute holds html content
8              definition.setName("API_CREATED");
9              definition.setPropertyType(PropertyType.STRING);
10
11
12              //Set ClientID to create attribute on sub-account
13              ConfigureOptions options = new ConfigureOptions();
14             //ClientID clientID = new ClientID();
15              //clientID.setPartnerClientKey(account.getCustomerKey());
16              //options.setClient(clientID);  //this creates attribute in sub-account
17              //definition.setClient(clientID); //this creates attribute in parent-account
18       ConfigureRequestMsg.Configurations configuration = new ConfigureRequestMsg.Configurations();
19       configuration.getConfiguration().addAll(Arrays.asList(definition));
20
21       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());
28
29    } catch (Exception e) {
30                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
31
32        }
33    }

Sample SOAP Envelope 

1<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
2 <s:Header>
3  <a:Action s:mustUnderstand="1">Configure</a:Action>
4  <a:MessageID>urn:uuid:730473d2-bc0c-4a96-bcb5-36000c55dc33</a:MessageID>
5  <a:ReplyTo>
6   <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
7  </a:ReplyTo>
8  <a:To s:mustUnderstand="1">https://YOUR_SUBDOMAIN.soap.marketingcloudapis.com/Service.asmx</a:To>
9  <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
10   <u:Timestamp u:Id="_0">
11    <u:Created>2009-09-16T15:53:40.216Z</u:Created>
12    <u:Expires>2009-09-16T15:58:40.216Z</u:Expires>
13   </u:Timestamp>
14   <o:UsernameToken u:Id="uuid-05561d8a-6ec8-4bb4-aa71-e4c0c6f385c8-1">
15    <o:Username>XXXXX</o:Username>
16    <o:Password>XXXXX</o:Password>
17   </o:UsernameToken>
18  </o:Security>
19 </s:Header>
20 <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
21  <ConfigureRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
22   <Options>
23   </Options>
24   <Action>Create</Action>
25   <Configurations>
26    <Configuration xsi:type="PropertyDefinition">
27     <PartnerKey xsi:nil="true">
28     </PartnerKey>
29     <ObjectID xsi:nil="true">
30     </ObjectID>
31     <Name>New_Attribute_Name</Name>
32     <PropertyType>string</PropertyType>
33    </Configuration>
34   </Configurations>
35  </ConfigureRequestMsg>
36 </s:Body>
37</s:Envelope>