I am trying to make soap call to get data from 3rd party website. How can i use soap api call in magento2 ?
2 Answers
Inject \Magento\Framework\Webapi\Soap\ClientFactory
in the class where you need it:
public function __construct(\Magento\Framework\Webapi\Soap\ClientFactory $soapClientFactory)
{
$this->soapClientFactory = $soapClientFactory;
}
Then use it to instantiate a SoapClient
instance:
$soapClient = $this->soapClientFactory->create($wsdl, $options);
For the parameters $wsdl
and $options
as well as usage examples, please refer to the PHP documentation:
-
hi Fabian, i tried the code and then discovered, a missing "create" should you now "create it", like $soapClient = $this->soapClientFactory->create( $wsdl, $options );– EvrijnCommented May 9, 2018 at 9:51
You can use zend soap like this.
$api = new \Zend\Soap\Client(NULL, $options);
-
For the one who's looking this in 2024, please note the
\Zend\Soap\Client
is removed since Magento 2.4.6. You should use\Laminas\Soap\Client
instead.– PY YickCommented Jun 7 at 8:42