Search code examples
phpsoap-client

PHP SoapClient - Soap call with nested parameters


If I have the following soap envelope how do I include the nested parameters for date range in my soap call?

<GetOrders xmlns="http://example.com/">
  <token>string</token>
  <CustomerId>integer</CustomerId>
  <DateRange>
    <MinimumDate xmlns="http://example.com">dateTime</MinimumDate>
    <MaximumDate xmlns="http://example.com">dateTime</MaximumDate>
  </DateRange>
</GetOrders>

$soap = new SoapClient('link/to/.wsdl');
$result = $soap->__soapCall('GetOrders', array('token' => 'asdad', 'CustomerId' => 1, 'MinimumDate' => '2018-10-01', 'MaximumDate' => '2018-10-16'));
var_dump($result);

Solution

  • By using nested in array:

    $result = $soap->__soapCall('GetOrders', 
        array('token' => 'asdad', 'CustomerId' => 1, 
        'DateRange' => array('MinimumDate' => '2018-10-01', 'MaximumDate' => '2018-10-16')
    ));