I'm using my custom API for getting some entities. I would like to filter items by Id. Here is the fragment of webapi.xml:

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
    <route url="/V1/opencGCApiGcapiapi/list/:products" method="GET">
        <service class="Openc\GCApi\Api\GcapiapiInterface"  method="list"/>
            <resource ref="anonymous"/>
            <parameter name="products" force="true">products</parameter>

I'm using this PHP code for testing:

$request = new SoapClient($wsdlUrl, ['version' => SOAP_1_2, 'context' =>context]);                                                              
$result = $request->opencGCApiGcapiapiV1List(array('products' => array(1,2)));

In my method I've added logging:

public function list($products  = NULL)
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
    $logger = new \Zend\Log\Logger();
    $logger->info(print_r($products, true));

In the log file I get the following record:

2017-11-02T14:50:48+00:00 INFO (6): Array

But I can not get the array contents.

Is it possible to pass arrays into the API's function?

  • please, add phpdoc for list to question – Max Nov 2 '17 at 15:17
  • Sorry, what do you mean by "phpdoc"? – Helmsmantest Nov 2 '17 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.