This is a php library for accessing a subset of ExactTarget's SOAP API. It provides synchronous CRUD operations on Data Extensions and Subscriber Lists by exposing a Doctrine-like API (Record, Table, Collection). The ExactTarget API documentation can be found here.
- See ExactTarget PHP getting started guide.
- If you are not using an auto-loader you will have to add require() statements.
To interact with the Soap API the library provides the basic classes that represent a Record, Table and Collection.
The names are pretty self explanatory and if you are familiar with Doctrine this will be very familiar.
- The record class allows for manipulation of a single record (CRUD).
- The table class exposes queries on the entire table and returns one or more records in form of a collection.
- A collection is a container class that holds a variable number of record objects and provides various methods to iterate over them or to create, update or delete them with a single operation.
To interact with a Data Extension with the following schema you simply extend the AbstractETDataExtensionObject
and AbstractETDataExtension
classes.
<?php
id (primary key)
firstname
lastname
email
<?php
class PersonDataExtensionObject extends AbstractETDataExtensionObject
{
protected function configure()
{
$this->customerKey = 'my customer key for this DE';
$this->schema = array(
'id' => array(
'is_primary' => true,
'is_required' => true,
'type' => self::TYPE_NUMBER),
'firstname' => array(
'is_primary' => false,
'is_required' => false,
'type' => self::TYPE_TEXT),
'lastname' => array(
'is_primary' => false,
'is_required' => false,
'type' => self::TYPE_NUMBER),
'email' => array(
'is_primary' => false,
'is_required' => true,
'type' => self::TYPE_NUMBER)
);
}
}
<?php
class PersonDataExtension extends AbstractETDataExtension
{}
Important: The two related classes must have the same name, but the Record class has Object
appended to it.
<?php
ETCore::initialize('myusername', 'mypassword');
$personDE = new PersonDataExtension();
$allPeople = $personDE->findAll(ETCore::HYDRATE_RECORD);
$person = $allPeople->getFirst();
$person->setfirstname('Joe');
$person->save();
<?php
ETCore::initialize('myusername', 'mypassword');
$personData = array(
'id' => 123,
'firstname' => 'Joe',
'lastname' => 'Smith',
'email' => '[email protected]'
);
$person = new PersonDataExtensionObject();
$person->fromArray($personData);
$person->save();
Please refer to the LICENSE file in this repository.
ExactTarget is a registered trademark of ExactTarget, Inc.