Wednesday, 27 March 2013

Enable Template/Block Hints in in Code magento

File: /app/code/core/Mage/Core/Block/Template.php (Magento 1.3.2)
public function getShowTemplateHints()
{
    if (is_null(self::$_showTemplateHints)) {
        self::$_showTemplateHints = Mage::getStoreConfig('dev/debug/template_hints')
            && Mage::helper('core')->isDevAllowed();
        self::$_showTemplateHintsBlocks = Mage::getStoreConfig('dev/debug/template_hints_blocks')
            && Mage::helper('core')->isDevAllowed();
    }
    return self::$_showTemplateHints;
}

Wednesday, 20 March 2013

How to configure Google Analytics in Magento from admin?


To configure Google Analytics tracking in Magento please navigate to System > Configuration > Sales > Google API screen in Magento backend and set tracking account ID into Google Analytics / Account Number field and finally click on Save button:

to find the text width in Zend pdf

 private function getTextWidth($text, Zend_Pdf_Resource_Font $font, $font_size)
    {
        $drawing_text = iconv('', 'UTF-16BE', $text);
        $characters    = array();
        for ($i = 0; $i < strlen($drawing_text); $i++) {
            $characters[] = (ord($drawing_text[$i++]) << 8) | ord ($drawing_text[$i]);
        }
        $glyphs        = $font->glyphNumbersForCharacters($characters);
        $widths        = $font->widthsForGlyphs($glyphs);
        $text_width   = (array_sum($widths) / $font->getUnitsPerEm()) * $font_size;
        return $text_width;
    }

Tuesday, 19 March 2013

How can you integrate the CDN with Magento?

Migrate content to CDN
  1. Login to the Magento Admin Panel.
  2. Navigate to Magento Admin > Configuration > Web > Unsecure.
  3. Update the following with the CDN URL(eg, cdn.magento.com):
    1. Base Media URL: cdn.yourmagento.com/media/
    2. Base Javascript URL: cdn.yourmagento.com/js/
  4. Click Save to update the changes.
  5. Then Navigate to Magento Admin > Configuration > Current Configuration Scope: Main Website > Web > Unsecure > Base Skin URL.
  6. Untick Use Default for the Base Skin URL
  7. Update Base Skin URL:
    1. Base Skin URL: cdn.yourmagento.com/skin/
  8. Click Save to update the changes.
Verification
Verify if your Magento is on CDN by viewing the HTML source code. Image links shall be replaced with CDN URLs.

setup cdn source http://www.riyaz.net/blogging/setup-own-cdn/890/

Sunday, 17 March 2013

Improving Magento Speed & Performance With MySQL Query Cache

Improving Magento Speed & Performance With MySQL Query Cache



http://www.crucialwebhost.com/blog/improving-magento-speed-and-performance-with-mysql-query-cache/

mysql configuration checks

http://dev.mysql.com/doc/refman/5.0/en/query-cache-configuration.html

magento can be speedup for apache server by setting up cache control
# 1 YEAR
Header set Cache-Control “max-age=29030400,public”
# 1 WEEK
Header set Cache-Control “max-age=604800,public”
# 2 DAYS
Header set Cache-Control “max-age=172800,proxy-revalidate”
Also try installing eAccelerator

Magento zgzip compression


Find the following lines in your Magento .htaccess file and replace them with the following code.
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary
# enable resulting html compression
php_flag zlib.output_compression on

source: http://inchoo.net/ecommerce/magento/boost-the-speed-of-your-magento/

Wednesday, 13 March 2013

To call packback webservice call to check mobile valid or not

<?php
echo validatePaybackMobile('9949123456');
function validatePaybackMobile($mobile){
    require_once('nusoap.php');
    if(strlen($mobile)!=10){
        $err="Mobile number should be 10 characters";
        return $err;
    }
    $bodyxml = '<?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.payback.net/lmsglobal/ws/v1/extint/types">
       <soapenv:Header/>
       <soapenv:Body>
          <typ:IsMobileLinkedRequest>
             <typ:MobileNumber>'.$mobile.'</typ:MobileNumber>
          </typ:IsMobileLinkedRequest>
       </soapenv:Body>
    </soapenv:Envelope>
    ';
  
  
    $client = new nusoap_client("https://46.51.221.138/PBExternalServices/v1/soap?wsdl",true);
    $err = $client->getError();
      
    $client->soap_defencoding = 'utf-8';
    $client->useHTTPPersistentConnection();
    $bsoapaction = "http://somehost/SubmitCalls";
    $result = $client->send($bodyxml, $bsoapaction);
    if($result['Status']=='YES'){
        return true;
    }
    elseif ($result['Status']=='NO') {
        $err="Mobile number is not exists in payback account, please check in your payback account";
        return $err;
    }else{
        return $err;
    }

Wednesday, 6 March 2013

Magento Rest APi

Tuesday, 5 March 2013

Creating a Custom API or Extending the Core API

The Core API allows you to manage a set of common resources used in Magento. However, you may choose to have your own set of resources to manage, or you may wish to extend the Core API to handle additional resources.
This tutorial leads you through the process of creating a custom API for a customer module that handles basic customer information.
Note: This tutorial applies to v1 of the API.
To learn more about the Core API, to read Magento Core API calls.
For general information about the Magento API, go to the Introduction.

1. Creating an XML File that Will Define the API Resource

Create a file named api.xml in the /etc folder in the customer module. Start with the empty structure, as follows:
<config>
    <api>
        <resources>
        </resources>
        <acl>
            <resources>
                <all>
                </all>
            </resources>
        </acl>
    </api>
</config>

2. Adding a Resource Named Customer

Add an element named customer in the <resources> element. Add a <methods> element, with elements for list, create, info, update and remove methods for customer resource.
Note that:
  • list will return all customers
  • create will create a new customer
  • info will return data on a specified customer
  • update will update data on a specified customer
  • remove will delete data on a specified customer
<config>
    <api>
....
        <resources>
            <customer translate="title" module="customer">
                <title>Customer Resource</title>
                <methods>
                    <list translate="title" module="customer">
                        <title>Retrive customers</title>
                    </list>
                    <create translate="title" module="customer">
                        <title>Create customer</title>
                    </create>
                    <info translate="title" module="customer">
                        <title>Retrieve customer data</title>
                    </info>
                    <update translate="title" module="customer">
                        <title>Update customer data</title>
                    </update>
                    <delete>
                        <title>Delete customer</title>
                    </delete>
                </methods>
                <faults module="customer">
                </faults>
            </customer>
        </resources>
....
    </api>
</config>

3. Adding Faults

The resource can return some faults, so add a <faults> element in the customer element, and list the various faults.
<config>
    <api>
....
        <resources>
            <customer translate="title" module="customer">
....
                <faults module="customer"> <!-- module="customer" specifies the module which will be used for translation. -->
                    <data_invalid> <!-- if we get invalid input data for customers -->
                        <code>100</code >
                        <!-- we cannot know all the errors that can appear, their details can be found in error message for call -->
                        <message>Invalid customer data. Details in error message.</message>
                    </data_invalid>
                    <filters_invalid>
                        <code>101</code >
                        <message>Invalid filters specified. Details in error message.</message>
                    </filters_invalid>
                    <not_exists>
                        <code>102</code >
                        <message>Customer doesn't exist.</message>
                    </not_exists>
                    <not_deleted>
                        <code>103</code >
                        <message>Customer was not deleted. Details in error message.</message>
                    </not_deleted>
                </faults>
            </customer>
        </resources>
....
    </api>
</config>

4. Describing the Access Control List (ACL) for the Resource

In order to prevent unauthorized access to our custom API, you must first list the resources that are restricted within the <acl> element.
<config>
    <api>
....
        <acl>
            <resources>
                    <customer translate="title" module="customer">
                         <title>Customers</title>
                         <list translate="title" module="customer">
                            <title>View All</title>
                         </list>
                         <create translate="title" module="customer">
                            <title>Create</title>
                         </create>
                         <info translate="title" module="customer">
                            <title>Get Info</title>
                         </info>
                         <update translate="title" module="customer">
                            <title>Update</title>
                         </update>
                         <delete translate="title" module="customer">
                            <title>Delete</title>
                         </delete>
                    </customer>
            </resources>
        </acl>
    </api>
</config>
Then, map ACL resources to API resource methods by adding an <acl> element to each part of the resource that needs restricting:
<config>
    <api>
        <resources>
            <customer translate="title" module="customer">
                <title>Customer Resource</title>
                <acl>customer</acl>
                <methods>
                    <list translate="title" module="customer">
                        <title>Retrive customers</title>
                        <acl>customer/list</acl>
                    </list>
                    <create translate="title" module="customer">
                        <title>Create customer</title>
                        <acl>customer/create</acl>
                    </create>
                    <info translate="title" module="customer">
                        <title>Retrieve customer data</title>
                        <acl>customer/info</acl>
                    </info>
                    <update translate="title" module="customer">
                        <title>Update customer data</title>
                        <acl>customer/update</acl>
                    </update>
                    <delete>
                        <title>Delete customer</title>
                        <acl>customer/delete</acl>
                    </delete>
                </methods>
              ....
            </customer>
        </resources>
....
    </api>
</config>

5. Creating PHP Code

Next, write some PHP code to access the resources. Start by creating a class called Mage_Customer_Model_Api that extends Mage_Api_Model_Resource_Abstract. Save it into a file called api.php.
class Mage_Customer_Model_Api extends Mage_Api_Model_Resource_Abstract
{

    public function create($customerData)
    {
    }

    public function info($customerId)
    {
    }

    public function items($filters)
    {
    }

    public function update($customerId, $customerData)
    {
    }

    public function delete($customerId)
    {
    }
}
Note that you cannot create method “list” because it’s a PHP keyword, so instead the method is named items. In order to make this work, add a <method> element into the <list> element in api.xml, as shown below.
<config>
    <api>
        <resources>
            <customer translate="title" module="customer">
                <model>customer/api</model> <!-- our model -->
                <title>Customer Resource</title>
                <acl>customer</acl>
                <methods>
                    <list translate="title" module="customer">
                        <title>Retrive customers</title>
                        <method>items</method> <!-- we have another method name inside our resource -->
                        <acl>customer/list</acl>
                    </list>
....
                </methods>
....
        </resources>
....
    </api>
</config>
Now add some simple functionality to the Mage_Customer_Model_Api methods you created.
Create a customer:
public function create($customerData)
    {
        try {
            $customer = Mage::getModel('customer/customer')
                ->setData($customerData)
                ->save();
        } catch (Mage_Core_Exception $e) {
            $this->_fault('data_invalid', $e->getMessage());
            // We cannot know all the possible exceptions,
            // so let's try to catch the ones that extend Mage_Core_Exception
        } catch (Exception $e) {
            $this->_fault('data_invalid', $e->getMessage());
        }
        return $customer->getId();
    }
Retrieve customer info:
public function info($customerId)
    {
        $customer = Mage::getModel('customer/customer')->load($customerId);
        if (!$customer->getId()) {
            $this->_fault('not_exists');
            // If customer not found.
        }
        return $customer->toArray();
        // We can use only simple PHP data types in webservices.
    }
Retrieve list of customers using filtering:
public function items($filters)
    {
        $collection = Mage::getModel('customer/customer')->getCollection()
            ->addAttributeToSelect('*');

        if (is_array($filters)) {
            try {
                foreach ($filters as $field => $value) {
                    $collection->addFieldToFilter($field, $value);
                }
            } catch (Mage_Core_Exception $e) {
                $this->_fault('filters_invalid', $e->getMessage());
                // If we are adding filter on non-existent attribute
            }
        }

        $result = array();
        foreach ($collection as $customer) {
            $result[] = $customer->toArray();
        }

        return $result;
    }
Update a customer:
public function update($customerId, $customerData)
    {
        $customer = Mage::getModel('customer/customer')->load($customerId);

        if (!$customer->getId()) {
            $this->_fault('not_exists');
            // No customer found
        }

        $customer->addData($customerData)->save();
        return true;
    }
Delete a customer:
public function delete($customerId)
    {
        $customer = Mage::getModel('customer/customer')->load($customerId);

        if (!$customer->getId()) {
            $this->_fault('not_exists');
            // No customer found
        }

        try {
            $customer->delete();
        } catch (Mage_Core_Exception $e) {
            $this->_fault('not_deleted', $e->getMessage());
            // Some errors while deleting.
        }

        return true;
    }

Creating a Custom Adapter

In order to create custom webservice adapter, implement the Mage_Api_Model_Server_Adapter_Interface, which is shown below.
interface Mage_Api_Model_Server_Adapter_Interface
{
    /**
     * Set handler class name for webservice
     *
     * @param string $handler
     * @return Mage_Api_Model_Server_Adapter_Interface
     */
    function setHandler($handler);

    /**
     * Retrive handler class name for webservice
     *
     * @return string [basc]
     */
    function getHandler();

    /**
     * Set webservice api controller
     *
     * @param Mage_Api_Controller_Action $controller
     * @return Mage_Api_Model_Server_Adapter_Interface
     */
    function setController(Mage_Api_Controller_Action $controller);

    /**
     * Retrive webservice api controller
     *
     * @return Mage_Api_Controller_Action
     */
    function getController();

    /**
     * Run webservice
     *
     * @return Mage_Api_Model_Server_Adapter_Interface
     */
    function run();

    /**
     * Dispatch webservice fault
     *
     * @param int $code
     * @param string $message
     */
    function fault($code, $message);

} // Class Mage_Api_Model_Server_Adapter_Interface End
Here is an example implementation for XML-RPC:
class Mage_Api_Model_Server_Adapter_Customxmlrpc
    extends Varien_Object
    implements Mage_Api_Model_Server_Adapter_Interface
{
     /**
      * XmlRpc Server
      *
      * @var Zend_XmlRpc_Server
      */
     protected $_xmlRpc = null;

     /**
     * Set handler class name for webservice
     *
     * @param string $handler
     * @return Mage_Api_Model_Server_Adapter_Xmlrpc
     */
    public function setHandler($handler)
    {
        $this->setData('handler', $handler);
        return $this;
    }

    /**
     * Retrive handler class name for webservice
     *
     * @return string
     */
    public function getHandler()
    {
        return $this->getData('handler');
    }

     /**
     * Set webservice api controller
     *
     * @param Mage_Api_Controller_Action $controller
     * @return Mage_Api_Model_Server_Adapter_Xmlrpc
     */
    public function setController(Mage_Api_Controller_Action $controller)
    {
         $this->setData('controller', $controller);
         return $this;
    }

    /**
     * Retrive webservice api controller
     *
     * @return Mage_Api_Controller_Action
     */
    public function getController()
    {
        return $this->getData('controller');
    }

    /**
     * Run webservice
     *
     * @param Mage_Api_Controller_Action $controller
     * @return Mage_Api_Model_Server_Adapter_Xmlrpc
     */
    public function run()
    {
        $this->_xmlRpc = new Zend_XmlRpc_Server();
        $this->_xmlRpc->setClass($this->getHandler());
        $this->getController()->getResponse()
            ->setHeader('Content-Type', 'text/xml')
            ->setBody($this->_xmlRpc->handle());
        return $this;
    }

    /**
     * Dispatch webservice fault
     *
     * @param int $code
     * @param string $message
     */
    public function fault($code, $message)
    {
        throw new Zend_XmlRpc_Server_Exception($message, $code);
    }
} // Class Mage_Api_Model_Server_Adapter_Customxmlrpc End
Notes: The setHandler, getHandler, setController and getController methods have a simple implementation that uses the Varien_Object getData and setData methods.
The run and fault methods are a native implementation for an XML-RPC webservice. The run method defines webservice logic in this adapter for creating an XML-RPC server to handle XML-RPC requests.
public function run()
    {
        $this->_xmlRpc = new Zend_XmlRpc_Server();
        $this->_xmlRpc->setClass($this->getHandler());
        $this->getController()->getResponse()
            ->setHeader('Content-Type', 'text/xml')
            ->setBody($this->_xmlRpc->handle());
        return $this;
    }
The “fault” method allows you to send fault exceptions for XML-RPC service when handling requests.
public function fault($code, $message)
    {
        throw new Zend_XmlRpc_Server_Exception($message, $code);
    }

Common Error Messages

The following are common error messages that you might receive when creating your own custom API.
Invalid API path
This error occurs when the methods listed in the api.xml file do not correspond exactly with those used in your PHP file.
For example, in your api.xml file, you might have this:
<config>
    <api>
        <resources>
            <checkout_cart translate="title" module="checkout">
                <model>checkout/cart_api</model>
                <title>Cart API</title>
                <methods>
                    <list translate="title" module="checkout">
                        <title>Retrieve cart data</title>
                        <method>info</method>
                    </list>
                </methods>
            </checkout_cart>
        </resources>
    ...
    </api>
</config>
You should have a corresponding info method in your PHP file.
class Mage_Checkout_Model_Cart_Api extends Mage_Cart_Model_Api_Resource
{
    public function info()
    {
        ...
    }
}
If you are missing this method, the error “Invalid api path” will be returned.

Source: http://www.magentocommerce.com/api/soap/create_your_own_api.html

Magento API / web service work

Magento has strong web service features. I can say Magento’s web service is one step ahead than others e-commerce. Magneto has soap, v2_soap(soap 2) and xmlrpc adapter facilities. Using magento web services you can synchronize customer, categories, products, orders etc data with existing stores. Here I am going to describe magento’s web service deals step by step.
Setup API: At first create api user and api key from Magento’s admin. Follow below steps.
1. Create api user from admin->system->web services-> Users->Add New User->User Info. See picture.
Api user create with api key
Api user create with api key
2. Create role to set permission on api method under admin->system->web services-> Roles->Add New Role.
3. Define “Role Resources” for created role. See picture.
Set api permission on role
Set api permission on role
4. Set “User Role” from admin->system->web services-> Users->choose user->User Role.
Call API:
API user and key is created. Now we can call api methods in two ways.
1. Soap call
2. V2_Soap call
Here I am going to discuss both ways.
Soap call:
Magento wiki and help center have described this method. So who are beginner in web service work they can call magento api using this soap method. You get all api documentations in Magento site. Here is an example.
01//create soap object
02$proxy = new SoapClient('http://127.0.0.1/magento/api/soap/?wsdl');
03 
04// create authorized session id using api user name and api key
05// $sessionId = $proxy->login('apiUser', 'apiKey');
06$sessionId = $proxy->login('m4u_admin', '12345678');
07 
08 // Get customer info for customer id = 1
09$customerinfo = $proxy->call($sessionId, 'customer.info', 1);
10 
11print_r($customerinfo);

V2_Soap call:

V2_soap call is for advance user. Who are expert in web service work they can easily use this method to call any magento api method from remote place. Whose magento knowledge is zero they also can use this soap method to work with magento web service. But about this method you will not get any api documentation in Magento wiki. But I think it will easy for you.
Here I am going to describe a-z about v2_soap method as any beginner also can use this soap calling method.
01//create soap object
02$proxy = new SoapClient('http://127.0.0.1/magento/api/v2_soap/?wsdl');
03 
04// create authorized session id using api user name and api key
05// $sessionId = $proxy->login('apiUser', 'apiKey');
06$sessionId = $proxy->login('m4u_admin', '12345678');
07 
08 // Get customer info for customer id = 1
09$customerinfo = $proxy->customerCustomerInfo($sessionId,1);
10 
11print_r($customerinfo);
Which method you need to call?
At first decide which method you need to call of api. Suppose you want to retrieve customer info from Magento store. So you should call customer related api method to get customer info. But you donot know which method exactly you need. To view all available methods in your magento api please run http://127.0.0.1/magento/api/v2_soap/?wsdl. Now pick appropriate api method from wsdl operation list. Suppose I pick “customerCustomerInfo” method to get customer info.
1<operation name="customerCustomerInfo">
2   <documentation>Retrieve customer data</documentation>
3   <input message="typens:customerCustomerInfoRequest"/>
4   <output message="typens:customerCustomerInfoResponse"/>
5</operation>
What is request parameter?
From wsdl you get a clear concept about api request/input parameter. For “customerCustomerInfo” operation input message is “customerCustomerInfoRequest”. So you will get all input/request parameter info (name and type) to call customerCustomerInfo method in message “customerCustomerInfoRequest”. customerCustomerInfo has three request parameter such sessionid(string), customerid(int) and atribuates(Array).
1<message name="customerCustomerInfoRequest">
2    <part name="sessionId" type="xsd:string"/>
3    <part name="customerId" type="xsd:int"/>
4    <part name="attributes" type="typens:ArrayOfString"/>
5</message>  
So we can request customerCustomerInfo method as below.
// Get customer info for customer id = 1 and attribute is optional
$attribute = array(‘firstname’, ‘lastname’, ‘email’, ‘store_id’);
$customerinfo = $proxy->call($sessionId, ‘customer.info’, 1, $attribute);
see picture for details-

API v2_soap wsdl request and response message.
API v2_soap wsdl request and response message.

Magento Web service call methods

Examples

Request Example SOAP V1
$client = new SoapClient('http://magentohost/api/soap/?wsdl');

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

$result = $client->call($session, 'customer.info', '2');
var_dump($result);

// If you don't need the session anymore
//$client->endSession($session);
Request Example SOAP V2
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary

$result = $proxy->customerCustomerInfo($sessionId, '2');
var_dump($result);
Request Example SOAP V2 (WS-I Compliance Mode)
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey'));

$result = $proxy->customerCustomerInfo((object)array('sessionId' => $sessionId->result, 'customerId' => '2'));
var_dump($result->result);
Response Example SOAP V1
array
  'customer_id' => string '2' (length=1)
  'created_at' => string '2012-03-29 12:37:23' (length=19)
  'updated_at' => string '2012-03-30 12:59:21' (length=19)
  'increment_id' => null
  'store_id' => string '2' (length=1)
  'website_id' => string '2' (length=1)
  'confirmation' => null
  'created_in' => string 'English' (length=7)
  'default_billing' => null
  'default_shipping' => string '2' (length=1)
  'disable_auto_group_change' => string '0' (length=1)
  'dob' => null
  'email' => string 'john@example.com' (length=16)
  'firstname' => string 'johny' (length=5)
  'gender' => null
  'group_id' => string '1' (length=1)
  'lastname' => string 'doe' (length=3)
  'middlename' => null
  'password_hash' => string 'cccfb3ecf54c9644a34106783148eff2:sp' (length=35)
  'prefix' => null
  'rp_token' => string '15433dd072f1f4e5aae83231b93f72d0' (length=32)
  'rp_token_created_at' => string '2012-03-30 15:10:31' (length=19)
  'suffix' => null
  'taxvat' => null
 
 
Source: http://www.magentocommerce.com/api/soap/customer/customer.info.html 

Multi Web service calls


Supported types


The Magneto Core API supports SOAP and XML-RPC, where SOAP is the default protocol.

SOAP

To connect to Magento SOAP web services, load theWSDL into your SOAP client from either of these URLs:
  • http://mymagentohost/api/?wsdl
  • http://mymagentohost/api/soap/?wsdl
where mymagentohost is the domain for your Magneto host.
As of v1.3, you may also use the following URL to access the Magento API v2, which has been added to improve compatibility with Java and .NET:
  • http://mymagentohost/api/v2_soap?wsdl=1
The following PHP example shows how to make SOAP calls to the Magento API v1:
  1. $client = new SoapClient('http://mymagentohost/api/soap?wsdl');
  2.  
  3. // If somestuff requires api authentification,
  4. // then get a session token
  5. $session = $client->login('apiUser', 'apiKey');
  6.  
  7. $result = $client->call($session, 'somestuff.method');
  8. $result = $client->call($session, 'somestuff.method', 'arg1');
  9. $result = $client->call($session, 'somestuff.method', array('arg1', 'arg2', 'arg3'));
  10. $result = $client->multiCall($session, array(
  11.      array('somestuff.method'),
  12.      array('somestuff.method', 'arg1'),
  13.      array('somestuff.method', array('arg1', 'arg2'))
  14. ));
  15.  
  16.  
  17. // If you don't need the session anymore
  18. $client->endSession($session);

XML-RPC

To use XML-RPC, load the following URL into your XML-RPC client:
  • http://mymagentohost/api/xmlrpc/
where mymagentohost is the domain for your Magneto host.
The following PHP example shows how to make XML-RPC calls:
  1. $client = new Zend_XmlRpc_Client('http://youmagentohost/api/xmlrpc/');
  2.  
  3. // If somestuff requires api authentification,
  4. // we should get session token
  5. $session = $client->call('login', array('apiUser', 'apiKey'));
  6.  
  7. $client->call('call', array($session, 'somestuff.method', array('arg1', 'arg2', 'arg3')));
  8. $client->call('call', array($session, 'somestuff.method', 'arg1'));
  9. $client->call('call', array($session, 'somestuff.method'));
  10. $client->call('multiCall', array($session,
  11.      array(
  12.         array('somestuff.method', 'arg1'),
  13.         array('somestuff.method', array('arg1', 'arg2')),
  14.         array('somestuff.method')
  15.      )
  16. ));
  17.  
  18. // If you don't need the session anymore
  19. $client->call('endSession', array($session));
The XML-RPC only supports the version 1 of the Magento API.

API Methods


The following table contains the API methods that can be called from your SOAP or XML-RPC client on the Magento v1 API.
Method Description Return Value
startSession() Start the API session and return session ID. string
endSession(sessionId) End the API session. boolean
login(apiUser, apiKey) Start the API session, return the session ID and authorize the API user string
call(sessionId, resourcePath,array arguments) Call the API resource that is allowed in current session. See Note below. mixed
multiCall(sessionId, array calls,array options) Call the API resource’s methods that are allowed for current session. See Notes below. array
resources(sessionId) Return a list of available API resources and methods allowed for current session. array
globalFaults(sessionId) Return a list of fault messages and their codes that do not depend on any resource. array
resourceFaults(sessionId, resourceName) Return a list of the specified resource fault messages, if this resource is allowed in current session. array
Note: For call and multiCall, if no session is specified, you can call only resources that are not protected by ACL.
Note: For multiCall, if the “break” option is specified, multiCall breaks on first error.
The Magento API v2 does not support the call() and multiCall() methods, and instead provides a separate method for each API resource.

Global API Faults


The following table contains fault codes that apply to all API calls.
Fault Code Fault Message
0 Unknown Error
1 Internal Error. Please see log for details.
2 Access denied.
3 Invalid api path.
4 Resource path is not callable.

API Version v2


Since Magento 1.3, version v2 of the API has also been available. The main difference between v1 and v2 is that instead of using methods call and multiCall, it has separate methods for each action.
For example, consider the following PHP code using v1.
  1. $params = array(array(
  2.     'status'=>array('eq'=>'pending'),
  3.     'customer_is_guest'=>array('eq'=>'1'))
  4. ));
  5. $result = $client->call($sessionId, 'sales_order.list', $params);
With v2, the following code would be equivalent.
  1. $params = array('filter' => array(
  2.     array('key' => 'status', 'value' => 'pending'),
  3.     array('key' => 'customer_is_guest', 'value' => '1')
  4. ));
  5. $result = $client->salesOrderList($sessionId, $params);
Note that the WSDL for v1 and v2 are different. Note that in v1, customizing the API did not involve changing the WSDL. In v2, changes to the WSDL are required.
You can configure the v2 API to be WS-I compliant in the system configuration menu. To do this, set Services > Magento Core API > WS-I Compliance to Yes.
Note that the WSDL for the v2 API is different when in WS-I compliant mode.
Using the WS-I compliant v2 API WSDL, it is easy to automatically generate client classes for Java, .NET, and other languages using standard libraries.

Source: http://www.magentocommerce.com/wiki/doc/webservices-api/api

To see all methods in Webservice call

A simple request for the web services available functions solved the problem.

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

Magento Web service calls