I have an existing m1 site and a php script which uses the soap API to synchronize product information (read only). It is on a host I do not control and uses the litespeed server.
I have been trying to test the M2 soap API and it is doing my head in. I cannot seem to get the authorization working. Anything needing not authorization works fine, but anything needing authorization does not.
This script is put on the magento2 folder and here's the key piece
// echo "<p>result? ".$token->result; (that works!)
$opts = array(
'http'=>array(
'header' => 'Authorization: Bearer '.$token)
);
$context = stream_context_create($opts);
$services = "catalogProductRepositoryV1";
try{
$client = new SoapClient("http://".$host."/soap/default?wsdl&services=$services",array('soap_version' => SOAP_1_2));
$client->setStreamContext($context);
$response = $client->__getFunctions();
var_dump($response);
}...
It seems that no matter what I try, the part about setstreamcontext fails so I cannot use the authorization. I have tried passing it as a context
array element, streamcontext
array element, and using the setStreamContext
method, and nothing seems to work.
UPDATE: I first tried
$client = new SoapClient("http://".$host."/soap/default?wsdl&services=$services",array('soap_version' => SOAP_1_2, 'context'=>$context));
but that doesn't work either. According to PHP documentation, it should work though, as context for passing http header is a documented option. It should therefore pass the Authorization option through?
I am starting to suspect that the way php is set up on this server does not support this context part.
Which versions of PHP support this? Is there any way to do it with the PHP SOAP rather than Zend?