Multiple items with the same name in PHP SOAP Call

I know this question has been asked several times. I spent several hours reading and testing the proposed solutions, but no one works for my situation.

I need to send a SOAP request to an API, which may contain an element that repeats as follows:

<operationNumbers>
    <operationNumber>1234</operationNumber>
    <operationNumber>1235</operationNumber>
    <operationNumber>1236</operationNumber>
    <operationNumber>1237</operationNumber>
</operationNumbers>

I read that maybe I could do this:

  $buildRequest = Array(
      'myheader' => Array(
      'date' => MY_DATE,
      'id' => Array(
          'client' => CLIENT,
          'clientRef' => MYREF
          )
      ),
      'operationNumbers' => Array (
          Array('operationNumber' => '1234'),
          Array('operationNumber' => '1235')
      )
   ); 

   $request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );

Unfortunately, this does not work and leads to an “invalid request” if I send one operation number, for example:

 ...
  'operationNumbers' => Array (
      'operationNumber' => '1234'
   )
 ...

Request completed successfully. I tried soapVars / soapParams but can't get it working using this approach. Any hints / tips / help appreciated.

+4
source share
3

, .

 $operationNumbersArray = array('1234','1235');

 ...

       'operationNumbers' => array(
           'operationNumber' => $operationNumbersArray
        )

, , . API ( ).

+5

, :

$wsdl = 'https://your.api/path?wsdl';
$client = new SoapClient($wsdl);
$multipleSearchValues = [1, 2, 3, 4];
$queryData = ['yourFieldName' => $multipleSearchValues];
$results = $client->YourApiMethod($queryData);
print_r($results);
+3

For repeating structured elements see this post: PHP Duplicate SOAP element name

-1
source

Source: https://habr.com/ru/post/1568129/


All Articles