Magento 1.9 SOAP API – Call Not Working Solution

apimagento-1.9soapwsdl

I am facing a issue with the SOAP Call request in Magento ver 1.9.1.0. I have tested the code in my local site, it works fine, but when i move the code to my online server it is not working.

I have checked SOAP is enabled in server, Please find the code i used for SOAP call,

$host = "81.82.212.166:8888/magento/index.php"; 
    $username = 'XXXXX';
    $apikey= 'YYYYYYY';
    try
    {
        $client = new SoapClient("http://" . $host . "/api/V2_soap?wsdl=1"); //soap handle
        $session_id = $client->login($username, $apikey);
    } catch (SoapFault $fault)
    {
        trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
    }

When i run the above code faced below error,

Fatal error: SOAP Fault: (faultcode: WSDL, faultstring: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://81.82.212.166:8888/magento/index.php/api/V2_soap?wsdl=1' : failed to load external entity "http://81.82.212.166:8888/magento/index.php/api/V2_soap?wsdl=1" ) in /var/www/html/magento/ingram_import/ingram_category_import.php on line 59

Best Answer

Finally, i got it working by using 127.0.0.1 as hostname and used SOAP v2 Calls,

    $client = new SoapClient('http://127.0.0.1/magento/index.php/api/v2_soap/?wsdl');
    $username = 'XXXX';
    $apikey= 'YYYYY';

    $session = $client->login($username, $apikey);

    $result = $client->catalogCategoryInfo($session, '2');

    echo '<pre>' . print_r($result);