Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Uploading an image using API
 
Mister Kp
Jr. Member
 
Total Posts:  22
Joined:  2009-04-23
 

Hi everyone,

I’m trying to upload an image using the API (WSDL 2 @ http://mymagento/api/v2_soap?wsdl) but I always get (in Java & PHP) the same error:

“Cannot use object of type stdClass as array”

I tried the simplest code though:

<?php

$proxy 
= new SoapClient('http://mymagento/api/v2_soap?wsdl');
$sessionId $proxy->login('user''key');
$sku '31';

$newImage = array(
    
'file' => array(
        
'content' => base64_encode(file_get_contents('/urlImage/test.jpg')),
        
'mime'    => 'image/jpeg'
    
),
    
'label'    => "Item:" $sku,
    
'position' => 0,
    
'types'    => array('image''small_image''thumbnail' ),
    
'exclude'  => 0
);
try 
{
    $proxy
->catalogProductAttributeMediaCreate($sessionId$sku,$newImage,"0");
}
catch(Exception $e{
    
print( "Error assigning image to $sku: " $e->getMessage() . "\n" );
}


?>

Does anyone know what should I do to make it works ?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
frodefi
Jr. Member
 
Total Posts:  8
Joined:  2009-01-08
 

The example on this in the documentation
http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product_attribute_media

uses this form:
$imageFilename = $proxy->call($sessionId, ‘product_media.create’, array(’Sku’, $newImage));

Maybe the error is there? At least it worked for me.

Frode

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mister Kp
Jr. Member
 
Total Posts:  22
Joined:  2009-04-23
 

This example is only valid for the WSDL 1.

I can make it work that way with PHP, but I need to use Java. And the WSDL 1 is not working with Java.

When I try to use the WSDL 2, I can’t upload image. With PHP neither

 
Magento Community Magento Community
Magento Community
Magento Community
 
dave stockmann
Jr. Member
 
Total Posts:  28
Joined:  2009-04-26
 

I am experiencing the same problem with 1.3.2.1.  I know it worked using WSDL v2 and java before I upgraded.  I can’t remember for sure which version I was using at the time though, I think 1.3.1.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rossigee
Jr. Member
 
Total Posts:  7
Joined:  2009-04-26
 

Same here

http://www.magentocommerce.com/bug-tracking/issue?issue=6692

 
Magento Community Magento Community
Magento Community
Magento Community
 
dave stockmann
Jr. Member
 
Total Posts:  28
Joined:  2009-04-26
 

Thanks for reporting the bug.  Hopefully it get’s resolved soon.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top