I am new to SOAP Web Service API's and Magento. Can someone show me an example of SOAP API request to return information about a product?
4 Answers
I have a magento 1.9.x website and I have been using Soap WebService APIs for an internally developed Android Application for Order and Delivery Management.
To be able to use Soap WebServices, I followed the following steps:
Downloaded SoapUI
Installed SaopUI
Created a new project and provided "Initial WSDL" value as -
It exposed all the Soap bindings from my website
To use any webservice, login call is required to get the session id.
Login request would look like the content at
- For username and APIKey, I created a Role and User using "SAOP/XML RPC Roles" and "SAOP/XML RPC Users" menu item under System in Magento Backend.
- After providing the username and apikey, I was able to generate the session id
- Using Session Id I was able to call other APIs.
- To integrate in Andorid App, I used a Saop Library ksoap2-android and everything worked like a charm.
Their is a function called catalogProductInfo in magento soap api v2 which will give you the information about the product
To make the use of the soap api services you need to create soap user and password.
$client = new SoapClient('http://yourmagantohost/index.php/api/v2_soap?wsdl=1');
$session = $client->login('yourapikey','yourapipassword');
$result = $client->catalogProductInfo($session,12734); // 12734 is the product id replace with yours product id
echo "<pre>"; print_r($result);
-
Can i get help magento.stackexchange.com/q/263298/57334@Pradeep Sanku– zusCommented Feb 27, 2019 at 11:56
Add below script file in root of your magento directory and then run. It will give you product detail mentioned as sku,
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require('vendor/zendframework/zend-server/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client/Common.php');
$wsdlurl = 'http://localhost/magentoce27/index.php/soap/default?wsdl&services=catalogProductRepositoryV1';
$token = 'dx2x7pl5mxq9hp8jr8efcl5crv2pk699';
$opts = ['http' => ['header' => "Authorization: Bearer ".$token]];
$context = stream_context_create($opts);
//$arguments =
$serviceArgs = array('searchCriteria'=>
array('filterGroups' =>
array ('filters' =>
array('field' =>'sku',
'value' => '24-MB01' ,
'condition_type' => 'eq')
)
)
);
$soapClient = new \Zend\Soap\Client($wsdlurl);
$soapClient->setSoapVersion(SOAP_1_2);
$soapClient->setStreamContext($context);
$result = $soapClient->catalogProductRepositoryV1GetList($serviceArgs);//array('searchCriteria' => $serviceArgs));
//$result = $soapClient->customerCustomerRepositoryV1GetById(array('customerId' => 1));
/*'search_criteria'=>
array('filter_groups' =>
array ('filters' =>
array('field' =>'firstname',
'value' => 'Veronica' ,
'condition_type' => 'eq')
)
)
);*/
echo "<pre>"; print_r($result);
?>
Check this:
function getProductDetails($sku)
{
$user_name = 'xxxxxxx';
$api_key = 'xxxxxxxxxxxxxxxxxxxx';
$result = array();
try {
$client = new SoapClient(http://magentosite.com/api/v2_soap/?wsdl);
$session = $client->login($user_name, $api_key);
$result = $client->catalogProductInfo($session, $sku, '', '', 'SKU');
$client->endSession($session);
} catch (SoapFault $e) {
$this->error = 'Error!';
}
return $result;
}
$ProductDetails = $this->getProductDetails('SKU-123');
print_r($ProductDetails);
Result:
stdClass Object
(
[product_id] => 35
[sku] => SKU-123
[set] => 9
[type] => simple
[categories] => Array()
[websites] => Array
(
[0] => 1
)
[created_at] => 2016-04-29T16:25:26+05:30
[updated_at] => 2016-04-29 10:55:26
[type_id] => simple
[name] => Suspense Men's Solid Casual Shirt-Blue-XL
[description] => Suspense Men's Solid Casual Shirt
[short_description] => Suspense Men's Solid Casual Shirt
[weight] => 1.6000
[status] => 1
[url_key] => suspense-men-s-solid-casual-shirt-blue-xl
[url_path] => suspense-men-s-solid-casual-shirt-blue-xl-35.html
[visibility] => 1
[category_ids] => Array()
[has_options] => 0
[price] => 40.0000
[special_price] => 38.0000
[special_from_date] => 2016-04-29 00:00:00
[tax_class_id] => 2
[tier_price] => Array()
[meta_title] => Suspense Men's Solid Casual Shirt
[meta_keyword] => Suspense Men's Solid Casual Shirt
[meta_description] => Suspense Men's Solid Casual Shirt
[options_container] => container1
)