FuelSDK-PHP
Forked from Salesforce Marketing Cloud Fuel SDK for PHP, (*1)
Salesforce Marketing Cloud Fuel SDK for PHP is free to use but
are not official Salesforce Marketing Cloud products and should
be considered community projects. This SDK is not officially
tested or documented. For help on any Salesforce Marketing
Cloud Fuel SDK for PHP, please consult the Salesforce message
boards or the issues section of this repository. Salesforce
Marketing Cloud support is not available for this SDK., (*2)
Overview
The Fuel SDK for PHP provides easy access to Salesforce Marketing
Cloud's Fuel API Family services, including a collection of REST
and SOAP API. These APIs provide access to Salesforce Marketing
Cloud (previously called ExactTarget) functionality via common
collection types such as array/hash., (*3)
New Features in Version 1.1.0
-
namespace : namespace is introduced., (*4)
-
newly supported objects:, (*5)
- Result Message
- Data Extract
- Triggered Send Summary
-
composer autoload issue fix, (*6)
-
proxy : added proxy server support.
If your client application sits behind a proxy server, you
can use PHP SDK with following configuration settings in $params array.
- proxyhost
- proxyport
- proxyusername
- proxypassword
You can supply these configuration setting using $params
parameter passed to the constructor of ET_Client class., (*7)
-
jwt : jwt.php is removed from the project source tree
jwt.php removed and added as dependency in composer.json.
If you are manually downloading the project, call
composer update to get jwt downloaded., (*8)
-
soap-wsse : soap-wsse.php is removed from the project
source tree and added as dependency in composer.json.
If you are manually downloading the project, call
composer update to get the soap-wsse downloaded., (*9)
-
code refactor : code refactored to individual class
files. (under src/ directory)
Project tree structure is now changed to:, (*10)
- src : source files
- doc : SDK API documentation
- tests : unit test cases
- objsamples : sample files
-
unit test : added unit test cases (happy path for now)
using phpunit testing framework. (under tests/ directory), (*11)
-
API docs : added API documentation using phpdocumentor
framework. (under docs/ directory)
-
auto loader : integrated auto loader (spl_autoload_register)
for all source code under src/, tests/, objsamples/ directory.
Requirements
PHP Version >=5.6.24, (*12)
Extensions:
- openssl
- SOAP
- curl, (*13)
API Documentation
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm, (*14)
Installation
Instructions
Use composer to manage this project's dependencies. After installing
with composer, inspect the config.php.template file and plan your
$params array accordingly., (*15)
Composer
Add a dependency to composer require
phpguru/fuel-sdk-php to the require section of
your project's composer.json configuration file, and
then run composer update to install., (*16)
The following code is an example of a minimal composer.json file:, (*17)
{
"require": {
"phpguru/fuel-sdk-php": "dev-master"
}
}
Getting Started
Why this fork?
I am a Laravel developer who had to use this package inside of a
Symfony project. The installation and configuration instructions for the
original project
require you to create a config.php in the project root., (*18)
Well, in Symfony 3.3x, I found that this was the web folder, and that
config.php in the web folder was auto-generated by the
SensioDistributionBundle. This was breaking not only this package code,
but also phpunit testing ability. Therefore, in this fork:, (*19)
The requirement to use config.php in the web root has been completely removed., (*20)
In short, while the original project may work on it's own or in older PHP projects,
this version is designed to play nice with frameworks such as Symfony and Laravel., (*21)
What? No config.php?
See the updated $params array fields when instantiating the ET_Client and pass
your parameters there, instead., (*22)
Note: I tried to make this version backward-compatible with the 1.1.0 release,
from the original project maintainer, but your mileage may vary., (*23)
If you are building a HubExchange application for the
Interactive Marketing Hub then, you must also provide the
Application Signature (appsignature). Only change the value
for the defaultwsdl configuration item if instructed by ExactTarget., (*24)
See the ET_Client section below for details on how to specify these
values at the time the ET_Client object is instantiated.
This allows you to store the ClientID and ClientSecret values in a
database or other configuration storage mechanism., (*25)
If you have not registered your application or you need to lookup
your Application Key or Application Signature values, please go
to Salesforce Marketing Cloud App Center., (*26)
Example Request
All ExactTarget objects exposed through the Fuel SDK begin with be
prefixed with "ET_". Start by working with the ET_List object:, (*27)
See the config.php.template example (under vendor/phpguru/ using
composer), then update your $params array to use your clientId and clientSecret., (*28)
Add composer's auto generated autoload.php file, change the path according to your directory structure:, (*29)
require \_\_DIR\_\_ . '/../vendor/autoload.php';
In Symfony and Laravel, this is taken care of for you automatically., (*30)
Add use statement to reference the FuelSdk namespace:, (*31)
use FuelSdk\ET_Client;
use FuelSdk\ET_List;
Next, create an instance of the ET_Client class:, (*32)
$params = [ YOUR_PARAMS_HERE ];
$myclient = new ET_Client(false, true, $params);
Create an instance of the object type we want to work with:, (*33)
$getList = new ET_List();
Associate the ET_Client to the object using the authStub property:, (*34)
$getList->authStub = $myclient;
Utilize one of the ET_List methods:, (*35)
$getResponse = $getList->get();
Print out the results for viewing, (*36)
print_r($getResponse);
Example Output:, (*37)
ET_Get Object
(
[status] => 1
[code] => 200
[message] =>
[results] => Array
(
[0] => stdClass Object
(
[Client] => stdClass Object
(
[ID] => 1000001
[PartnerClientKey] =>
)
[PartnerKey] =>
[CreatedDate] => 2009-06-12T14:42:06.1
[ModifiedDate] => 2011-08-17T14:50:30.697
[ID] => 1718921
[ObjectID] => f41c7d1b-8957-de11-92ee-001cc494ae9e
[CustomerKey] => All Subscribers - 578623
[ListName] => All Subscribers
[Category] => 578623
[Type] => Private
[Description] => Contains all subscribers
[ListClassification] => ExactTargetList
)
)
[request_id] => 5d56a37e-4b13-4f0a-aa13-2e108e60a990
[moreResults] =>
)
ET_Client Class
The ET_Client class takes care of many of the required steps when accessing ExactTarget's API, including retrieving appropriate access tokens, handling token state for managing refresh, and determining the appropriate endpoints for API requests. In order to leverage the advantages this class provides, use a single instance of this class for an entire session. Do not instantiate a new ET_Client object for each request made., (*38)
The ET_Client class accepts 3 parameters., (*39)
Refresh WSDL - If set to true, it will automatically download a
local copy of the WSDL whenever an update is found., (*40)
Debug - If set to true, all API requests that the Fuel SDK is
making behind the scenes will be logged to PHP's error log.
This option should only be set to true in order to troubleshoot
during the development process and should never be used in a
production scenario., (*41)
Parameters - Allows for passing authentication information
for use with SSO with a JWT or for passing ClientID/ClientSecret
if you would prefer to not use the config file option., (*42)
Example passing JWT:, (*43)
$myclient = new ET_Client(false, true, array("jwt"=>"JWT Values goes here", ... ));
Example passing ClientID/ClientSecret:, (*44)
$myclient = new ET_Client(false, true, array("clientid" => "3bjbc3mg4nbk64z5kzczf89n", "clientsecret"=>"ssnGAPvZg6kmm775KPj2Q4Cs", ...));
The $params examples above are incomplete. Pass the entire array of
necessary params when instantiating the ET_Client object., (*45)
Responses
All methods on Fuel SDK objects return a generic object that follows
the same structure, regardless of the type of call. This object
contains a common set of properties used to display details about
the request., (*46)
- status: Boolean value that indicates if the call was successful
- code: HTTP Error Code (will always be 200 for SOAP requests)
- message: Text values containing more details in the event of an error
- results: Collection containing the details unique to the method called.
Get Methods also return an addition value to indicate if more information is available (that information can be retrieved using the getMoreResults method):, (*47)
- moreResults - Boolean value that indicates on Get requests if more data is available.
Samples
Find more sample files that illustrate using all of the available
functions for ExactTarget objects exposed through the API in the
objsamples directory., (*48)
Sample List (DEPRECATED):, (*49)