Reputation: 1936
I am trying to add an image to a product using magento's SOAP api and I can succesffully upload it using the standard SoapClient
but it fails if I use the Pear SOAP_Client
Here is what I'm doing with SoapClient
:
$image_data = array(
'file' => array(
'name' => 'test_image_name',
'content' => $content,
'mime' => 'image/jpeg'
),
'label' => 'test_image_label',
'position' => 1,
'types' => '',
'exclude' => 0
);
$client = new SoapClient($wsdl_url);
$session_id = $client->login($mg_user, $mg_key);
$magento_filename = $client->call($session_id, 'product_media.create', array(
$sku,
$image_data
));
And that will successfully add the image to the product.
But If I use SOAP_Client
:
$client = new SOAP_Client($wsdl_url, true);
$session_id = $client->call(
'login',
array(
'username'=>$mg_user,
'apiKey'=> $mg_key
)
);
$magento_filename = $client->call(
'call',
array(
'sessionId'=>$session_id,
'resourcePath'=>'product_media.create',
'args'=>array(
$sku,
$image_data,
)
)
);
I get the SOAPFault: "Cannot use object of type stdClass as array"
But I am able to call catalog_product.info:
$info = $client->call(
'call',
array(
'sessionId'=>$session_id,
'resourcePath'=>'catalog_product.info',
'args'=>array($sku)
)
);
and that returns all the correct data with no errors.
What could be causing the difference?
Upvotes: 1
Views: 665
Reputation: 31137
Do not use PEAR's SOAP package. It's outdated and was used before the PHP SoapClient was there.
Upvotes: 0
Reputation: 1936
My solution, which is really no solution at all, was to reconfigure and reinstall php with --enable-soap
.
But it might not be a feasible resort for others with the problem depending on their hosting scenarios.
Upvotes: 0