简体   繁体   中英

Magento : Soap api not working

Hi i am using magento vesion 1. 9 and i am trying to call magento soap apiv2 using php.

i use the following code.

$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$sessionId = $proxy->login((object)array('username' => 'user', 'apiKey' => 'password'));
$product=$proxy->catalogProductInfo((object)array('sessionId' => $sessionId->result, 'productId' => '27'));

i get the session id (i testes it by printing the id) but when i make a soap call

$product=$proxy->catalogProductInfo((object)array('sessionId' => $sessionId->result, 'productId' => '27'));

the browser showing "Server error"

api user having full permission in the back end. but still it is not working. please some one help me to find the solution.

Your code seems a bit bloated. Try this:

$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$sessionId = $proxy->login("username", "password");
$product = $proxy->catalogProductInfo($sessionId, '27');
print_r($product); // just to see the output

If you want to re-use the code I'd suggest the following anyway:

$host = "domain.ext"; // replace with your domain name
$username = "username"; // replace with your soap user
$password = "password"; // replace with your user's password
$productId = "27";

$proxy = new SoapClient("http://".$host."/index.php/api/v2_soap/?wsdl=1");
$sessionId = $proxy->login($username, $password);
$product = $proxy->catalogProductInfo($sessionId, $productId);

print_r($product); // just to see the output

A nice hint if you want to see what other functions are available:

$functions = $proxy->__getFunctions ();
var_dump($functions);

Hope it helps :)

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM