Search code examples
magentosoap-clientmagento-soap-api

Connecting to Magento API with SOAP


I'm trying to follow a tutorail on connecting to magento API with Soap, but am stuck already ? SOAP seems to be installed on my sever as i can browse to the ?wsld and it displays an xml file.

I've setup the user and role in magento admin webservices.

i'm confused by 2 things in the tutorial

  1. choosing a soap client, In this tutorial we will assume the usage of the PHP SoapClient. what is this where do i find it ?
  2. Logging with the SOAP client

"So let's create a simple PHP-script that allows us to login into Magento through SOAP. The logic is here that we first need to initialize a new SoapClient object with as argument the Magento SOAP URL."

 // Magento login information 
 $mage_url = 'http://MAGENTO/api/?wsdl'; 
$mage_user = 'soap_user'; 
$mage_api_key = '********'; 
// Initialize the SOAP client 
$soap = new SoapClient( $mage_url ); 
// Login to Magento 
$session_id = $soap->login( $mage_user, $mage_api_key );

Where do you create this script - is it a simple php file ? and how do you actualy make the call - do you just browse to it ?

http://blog.opensourcenetwork.eu/tutorials/guru/connecting-through-soap-with-magento-1

Many thanks in advance


Solution

  • You put this into a new blank file. Save this as name.php und run this is on your server:

    <?php
            $host = "127.0.0.1/magento/index.php"; //our online shop url
            $client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
            $apiuser= "user"; //webservice user login
            $apikey = "key"; //webservice user pass
            $action = "sales_order.list"; //an action to call later (loading Sales Order List)
            try { 
    
              $sess_id= $client->login($apiuser, $apikey); //we do login
    
    
            print_r($client->call($sess_id, $action));
            }
            catch (Exception $e) { //while an error has occured
                echo "==> Error: ".$e->getMessage(); //we print this
                   exit();
            }
    ?>
    

    Regards boti