Question

I'm working on a project where we need to extend Magento's SOAP Api--we want to add a method for an existing .NET application using WSI-compliance mode. I don't have access to this .NET application, so I'm trying to use PHP to make WSI-compliant calls into Magento, and I'm having some trouble with PHP's SoapClient. I can't seem to get a populated filters array through.

Specifically, I have a small test program that looks like this

$api = new SoapClient(
    'http://magento.example.com/index.php/api/v2_soap?wsdl=1',
    [   
        'soap_version'=>SOAP_1_2,
        'trace'=>1
    ]
);
$result = $api->login([
    'username'=>'apitest',
    'apiKey'=>'apitest1'
]);    
$session = $result->result;

$request = [
    'sessionId' =>$session,
    'filters'   => [
        'test'=>'foo'
    ]
];

$result = $api->salesOrderList($request);
var_dump($api->__getLastRequestHeaders());
var_dump($api->__getLastRequest());    

var_dump($result);

The program is able to successfully fetch a session id from the server. It's also able to successfully make a salesOrderList call into the server. However, the program is not able to successfully send a filters array through. That is, the __getLastRequest function above returns

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:Magento">
    <env:Body>
        <ns1:salesOrderListRequestParam>
            <sessionId>3590ffdb691bc65498dac32909d24da1</sessionId>
            <filters />
        </ns1:salesOrderListRequestParam>
    </env:Body>
</env:Envelope>

Does anyone know

  1. If it's possible, using the V2 SOAP Api with the WSI-Compliant WSDL, to get a filters array through in a SoapClient call.

  2. If not, does anyone know the proper format for the <filters/> XML of a SOAP request so I can modify it in a __doRequest method override.

  3. Alternately, is there a composer package that supports the more modern WSI-compliant WSDL? i.e. an alternate SoapClient.

Was it helpful?

Solution

Thanks to the help of SoapUI, I found the following request format would work using PHP SoapClient:

   $request = [ 
        'sessionId' => $session,
        'filters'   => [
          'filter' => [
            [   
              'key'   => 'status',
              'value' => 'pending'
            ]   
          ]   
        ]   
    ];

XML Request:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:Magento">
  <env:Body>
    <ns1:salesOrderListRequestParam>
      <sessionId>318ca8b59763279e9e4dbe969e5ec4e1</sessionId>
      <filters>
        <filter>
          <complexObjectArray>
            <key>status</key>
            <value>pending</value>
          </complexObjectArray>
        </filter>
      </filters>
    </ns1:salesOrderListRequestParam>
  </env:Body>
</env:Envelope>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top