Last active
December 28, 2019 03:31
-
-
Save kylekeesling/4493769 to your computer and use it in GitHub Desktop.
Example of Adding Data to an ExactTarget Data Extension via the SOAP API - API Starter Kit can be found here - http://docs.code.exacttarget.com/@api/deki/files/199/=PHP_APIstarterKit-V1.zip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
public function dataExtensionAdd($ExternalKey = '', $client = '') { | |
try { | |
/* Create the Soap Client */ | |
$soap = new EBG_ExactTarget_Client($this->wsdl, array('trace'=>1)); | |
/* Set username and password here */ | |
$soap->username = $this->username; | |
$soap->password = $this->password; | |
$DE = new ExactTarget_DataExtensionObject(); | |
//$DE->CustomerKey=$ExternalKey; //Same as external key in user interface | |
$DE->Name = 'NYDC Newsletter Subscriber Profile Data'; | |
// create clientid based on MID | |
$clientID = new ExactTarget_ClientID(); | |
$clientID->ID = $client; | |
$DE->Client = $clientID; | |
$apiProperty1 =new ExactTarget_APIProperty(); | |
$apiProperty1->Name="subscriberkey"; | |
$apiProperty1->Value="[email protected]"; | |
$apiProperty2 =new ExactTarget_APIProperty(); | |
$apiProperty2->Name="EmailAddress"; | |
$apiProperty2->Value="[email protected]"; | |
$apiProperty3 =new ExactTarget_APIProperty(); | |
$apiProperty3->Name="FirstName"; | |
$apiProperty3->Value="Bob"; | |
$apiProperty4 =new ExactTarget_APIProperty(); | |
$apiProperty4->Name="Salutation"; | |
$apiProperty4->Value="Mr"; | |
$DE->Properties=array($apiProperty1,$apiProperty2,$apiProperty3,$apiProperty4); | |
$Keys = new ExactTarget_APIProperty(); | |
$Keys->Name = "Email"; | |
$Keys->Value = '[email protected]'; | |
$DE->Keys = array($Keys); | |
$deoSaveOption = new SoapVar($DE, SOAP_ENC_OBJECT, 'DataExtensionObject', "http://exacttarget.com/wsdl/partnerAPI"); | |
$updateOptions = new ExactTarget_UpdateOptions(); | |
$updateOptions->SaveOptions = array(); | |
/*% ExactTarget_SaveOption */ | |
$saveOption = new ExactTarget_SaveOption(); | |
$saveOption->PropertyName="DataExtensionObject"; | |
$saveOption->SaveAction=ExactTarget_SaveAction::UpdateAdd; | |
$updateOptions->SaveOptions[] = $saveOption; | |
$updateOptionsSaveOptions = new SoapVar($updateOptions, SOAP_ENC_OBJECT, 'UpdateOptions', "http://exacttarget.com/wsdl/partnerAPI"); | |
// Apply options and object to request | |
$request = new ExactTarget_UpdateRequest(); | |
$request->Options = $updateOptionsSaveOptions; | |
$request->Objects = array($deoSaveOption); | |
$results = $soap->Update($request); | |
return $results; | |
} catch (SoapFault $e) { | |
/* output the resulting SoapFault upon an error */ | |
//var_dump($e); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On line #12 a CustomerKey must be used in order to interact w/ the Data Extensions