Thursday, 14 January 2016

XML : Assistance with PHP Soap request with attributes and nodes

I'm having an issue using the PHP Soap client to create the below XML Soap request. Problem I'm having is adding the fullName element as the child node to sObjects.

  <?xml version="1.0" encoding="UTF-8"?>  <x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn1="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <x:Header>      <urn1:SessionHeader>          <urn1:sessionId>a sessionid</urn1:sessionId>      </urn1:SessionHeader>      <urn1:MetadataWarningsHeader>          <urn1:ignoreSaveWarnings>false</urn1:ignoreSaveWarnings>      </urn1:MetadataWarningsHeader>      <urn1:AllOrNoneHeader>          <urn1:allOrNone>false</urn1:allOrNone>      </urn1:AllOrNoneHeader>      <urn1:CallOptions>          <urn1:client/>      </urn1:CallOptions>  </x:Header>  <x:Body>      <urn1:create>          <urn1:sObjects xsi:type="WorkflowFieldUpdate">              <fullName>Lead.Tooling</fullName>              <metadata>                  <field>Test_Field_Update__c</field>                  <name>Tooling</name>                  <notifyAssignee>false</notifyAssignee>                  <operation>Null</operation>                  <protected>false</protected>              </metadata>          </urn1:sObjects>      </urn1:create>  </x:Body>    

Here is the code I'm using in the create function. I get everything, but the fullName. I tried adding is as apart of an array with the Metadata node, but it's inserted as Bogus.

  $field = new SoapVar('Test_Field_Update__c', XSD_STRING, null, null, 'field', null);  $name = new SoapVar('ToolingSample', XSD_STRING, null, null, 'name', null);  $notifyAssignee = new SoapVar(false, XSD_BOOLEAN, null, null, 'notifyAssignee');  $protected = new SoapVar(false, XSD_BOOLEAN, null, null, 'protected');  $operation = new SoapVar('Null', XSD_STRING, null, null, 'operation');  $fullname = new SoapVar('Lead.ToolingSample', XSD_STRING, null, null, 'fullName', null);    $metadata = new SoapVar(      array($field, $name, $notifyAssignee, $protected, $operation),      SOAP_ENC_OBJECT,      null,      null,      'Metadata'  );  $metadataList = new SoapVar(array($metadata), SOAP_ENC_OBJECT);    $sObject = new SoapVar($metadataList, SOAP_ENC_OBJECT, 'WorkflowFieldUpdate', null, 'sObjects');  $sObjects = new SoapVar(array($sObject), SOAP_ENC_OBJECT, null, null, null);    $response = $soapClient->create(new SoapVar($sObjects, SOAP_ENC_OBJECT));    $ReturnArray = array('success' => true, 'data' => $response, 'types' => $metadataList, 'request' => $soapClient->__getLastRequest());    echo $_REQUEST['callback'] . '(' . json_encode($ReturnArray) . ')';    

I tried changing the sObject Soapvar to this, but no go. I wasn't too confident it would work.

  $sObject = new SoapVar(array($fullName, $metadataList), SOAP_ENC_OBJECT, 'WorkflowFieldUpdate', null, 'sObjects')    

No comments:

Post a Comment