0

I am new to api. Can anyone guide how to add product using SOAP api.

1 Answer 1

1

Use below code to add product using soap api.

$url = Mage::getBaseUrl().'api/soap/?wsdl';
$client = new SoapClient($url);

// If some stuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');

// get attribute set
$attributeSets = $client->call($session, 'product_attribute_set.list');
$attributeSet = current($attributeSets);


$result = $client->call($session, 'catalog_product.create', array('simple', $attributeSet['set_id'], 'product_sku', array(
    'categories' => array(2),
    'websites' => array(1),
    'name' => 'Product name',
    'description' => 'Product description',
    'short_description' => 'Product short description',
    'weight' => '10',
    'status' => '1',
    'url_key' => 'product-url-key',
    'url_path' => 'product-url-path',
    'visibility' => '4',
    'price' => '100',
    'tax_class_id' => 1,
    'meta_title' => 'Product meta title',
    'meta_keyword' => 'Product meta keyword',
    'meta_description' => 'Product meta description'
)));

var_dump ($result);

You can add this code in any controller and then call that controller action in frontend. Your product will be added.

7
  • I am getting this error - SOAP-ERROR: Parsing WSDL: Couldn't load from 'localhost/magento/api/soap/?wsdl' : failed to load external entity
    – jassi
    Mar 29, 2017 at 17:34
  • Replace $client = new SoapClient('magentohost/api/soap/?wsdl'); with $url = Mage::getBaseUrl().'api/soap/?wsdl'; $client = new SoapClient($url); Mar 30, 2017 at 4:51
  • Check my updated answer. Mar 30, 2017 at 4:52
  • I have enabled extension=php_openssl.dll in php.ini file, then that problem got solved. Thanks.
    – jassi
    Mar 30, 2017 at 4:59
  • I am getting access denied for $session = $client->login('apiUser', 'apiKey'); How to create apiUser and apiKey in magento 1.9?
    – jassi
    Mar 30, 2017 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.