PHP Calling SOAP [Encoding] with Exact Target WebServices API

Nerd Factor: 8

I am trying to call an Exact Target Web Services (SOAP) API via PHP and there is this problem where the __getLastRequest() is showing that my data isn’t actually being put into the request. It looks like I’m not passing any data aside from the basic XML showing the method name.

It has been a while since I ran into this issue and so I wanted to make note of it on a blog, somewhere indexed more thoroughly by Google, so the next person who ran into the problem would save a little time.

The skinny:  You need to explicitly encode the objects that are being sent to the service.

If you want to pass no data:

$sfs = new ExactTarget_SalesforceSend();
$sfs->Email = $e;
$sfs->Targets = array( $t );
$sfs->FromName = "Lead/Contact Owner Name";
$request = new ExactTarget_CreateRequest();
$request->Options = NULL;
$request->Objects = array($object);
$results = $client->Create($request);

If you do indeed want to pass data:

$sfs = new ExactTarget_SalesforceSend();
$sfs->Email = $e;
$sfs->Targets = array( $t );
$sfs->FromName = "Lead/Contact Owner Name";
$object = new SoapVar($sfs, SOAP_ENC_OBJECT, 'SalesforceSend', "http://exacttarget.com/wsdl/partnerAPI");
$request = new ExactTarget_CreateRequest();
$request->Options = NULL;
$request->Objects = array($object);
$results = $client->Create($request);

That bolded line tells php/soap that it needs to encode based on a specific element in the wsdl schema.  In other languages you can use wsdl2java and end up with classes that you can just pass along and they get serialized the right way.  PHP and other languages of that group (Perl, Ruby) need to explicitly encode the data that is being passed.  You would expect that passing an array/dictionary/object into the function expecting that element would work – but no – it just needs to be told ever so gently which data type it should use.

Of note:  I belive this may just happen when inheritance is used in publishing the web service (.Net and Java) which is represented in the wsdl file like this:

<extension base="tns:APIObject">

For Google, the error I was getting was:

Requested value 'APIObject' was not found.

sharing is good:
  • Digg
  • del.icio.us
  • Facebook
  • Reddit
  • Fark
  • TwitThis

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.