|
|
Documentation Wiki > Developer Documentation > Web Service Guide > Technical Articles > Adding an Attribute Via the Web Service API
Adding an Attribute Via the Web Service APIFrom $1Table of contents(Click the banner to go to the related Docs.Code.ExactTarget.com page.) This document contains conceptual and procedural information about adding an attribute via the web service API. Why Add an Attribute Via the Web Service APIYou can add an attribute in order to retain more information about your subscriber. This information gives you more information with which to better target or exclude subscribers from your sends. How To Add an Attribute Via the Web Service APIUse the sample code below as a model to construct your own API calls. You need to know the following information to create an attribute:
NOTE: You cannot create an attribute using the name of an already-existing attribute. When an attribute has been added to any list, it is available on all of the lists. Sample .NET Code// Initiate the variables string requestID = null; string status = null; string message = null;
// Create the PropertyDefinition object
PropertyDefinition propDef = new PropertyDefinition();
propDef.Name = "Company"; //Attribute Name
propDef.PropertyType = PropertyType.@string; //Attribute type [@string .net specific way to utilize our enumeration of string.]
propDef.PropertyTypeSpecified = true;
propDef.IsEditable = true; //indicating the attribute is editable on ET default profile center
propDef.IsEditableSpecified = true;
String requestId = null;
String status = null;
String message = null;
// Call the Configure command with the Action "create"
ConfigureResult[] results = client.Configure(null, "create", new APIObject[] { propDef }, out status, out message, out requestId);
//CreateResult[] results = client.Create(new CreateOptions(), apiObjects, out requestId, out status);
if (status == "Error")
{
lblMessage.Text = "Could not create attribute. " + results[0].StatusMessage;
}
else
{
lblMessage.Text = status;
}
Sample PHP Code<?php
require('exacttarget_soap_client.php');
$wsdl = 'https://webservice.exacttarget.com/etframework.wsdl';
try{
echo "1";
/* Create the Soap Client */
$client = new ExactTargetSoapClient($wsdl, array('trace'=>1));
/* Set username and password here */
$client->username = 'xxx';
$client->password = 'xxx';
//Create List Configuration Object
$pd = new ExactTarget_PropertyDefinition(); $pd->Name = 'BusinessAddress'; $pd->PropertyType = ExactTarget_PropertyType::string; $object = new SoapVar($pd, SOAP_ENC_OBJECT,'PropertyDefinition', "http://exacttarget.com/wsdl/partnerAPI");
$lstConf = new ExactTarget_ConfigureRequestMsg();
$lstConf->Configurations = array();
$lstConf->Configurations[] = $object;
$lstConf->Action = 'Create' ;
$results = $client->Configure($lstConf); var_dump($results); } catch (SoapFault $e) { var_dump($e); } ?>
Sample Java Code (Axis 1.4)public void testAddSubscriber() throws RemoteException {
Soap stub = init();
Subscriber subscriber = new Subscriber();
subscriber.setEmailAddress("acruz@example.com");
subscriber.setSubscriberKey(subscriber.getEmailAddress()); // unique identifier
subscriber.setStatus(SubscriberStatus.Active);
Attribute a1 = new Attribute();
a1.setName("ByAPI");
a1.setValue("Yes");
Attribute a2 = new Attribute();
a2.setName("frist_name");
a2.setValue("Angel");
subscriber.setAttributes(new Attribute[]{a1, a2});
APIObject[] apiObjects = {subscriber};
CreateRequest createRequest = new CreateRequest(new CreateOptions(), apiObjects);
CreateResponse createResponse = stub.create(createRequest);
System.out.println("Subscriber created in list ::: " + createResponse.getOverallStatus());
}
This page was last updated on Fri, 06 Jan 2012 21:25:07 GMT.
Tags: (Edit tags)
|
Powered by MindTouch 2010 |