Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Magento SOAP API

An introduction to extending the Magento SOAP API
by

Vinai Kopp

on 1 December 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Magento SOAP API

<?xml version="1.0"?>
<config>
<api>
<resources>
<my_soap_resource>
<model>MySOAP/api</model>
<title>Sample Api</title>
<acl>mysoap</acl>
<methods>
<myMethod>
<title>Trigger some SOAP action or get some data</title>
<acl>mysoap/mymethod</acl>
<method>myMethodName</method>
<arguments>array</arguments>
</myMethod>
</methods>
<faults>
<data_invalid>
<code>100</code>
<message>Invalid data. Details in error message.</message>
</data_invalid>
</faults>
</my_soap_resource>
</resources>
<resources_alias>
<mySoapResource>my_soap_resource</mySoapResource>
</resources_alias>
<v2>
<resources_function_prefix>
<mySoapResource>mySoap</mySoapResource>
</resources_function_prefix>
</v2>
<acl>
<resources>
<mysoap>
<title>Sample Api</title>
<sort_order>500</sort_order>
<mymethod>
<title>Trigger some SOAP action or get some data</title>
</mymethod>
</mysoap>
</resources>
</acl>
</api>
</config> etc/api.xml Structure v2 Requests: map Method Prefix to Resource $soap->mySoapMyMethod($sessionId, 'param1', 'param2'); SOAP API Call $soap->mySoapMyMethod();
"mySoapMyMethod" is mapped to "mySoapResource.myMethod" Found in Mage_Api_Model_Server_V2_Handler::__call() Found in Mage_Api_Model_Server_Handler_Abstract::call() "mySoapResource" is mapped to "my_soap_resource"
$resourceName = "my_soap_resource"
$methodName = "myMethod" <config>
<v2>
<resources_function_prefix>

<mySoapResource>mySoap</mySoapResource>

</resources_function_prefix>
</v2>
</config> $soap->call($sessionId, 'mySoap.myMethod', array('param1', 'param2'); API v2: API v1: the Magento SOAP API v1 & v2 Vinai Kopp, http://netzarbeiter.com/
for #magentodp2010 v1 AND v2 Requests: resolve Resource Aliases <config>
<api>
<resources_alias>

<mySoapResource>my_soap_resource</mySoapResource>

</resources_alias>
</api>
</config> "mySoapResource.myMethod"
$resourceName = "mySoapResource"
$methodName = "myMethod" 1. 2. Found in Mage_Api_Model_Server_Handler_Abstract::call() authenticate Resource <config>
<api>
<resources>
<my_soap_resource>

<acl>mysoap</acl>
<!-- or <public>1</public> -->

</my_soap_resource>
</resources>

<acl>
<resources>
<mysoap>
<title>Sample Api</title>
</mysoap>
</resources>
</acl>
</api>
</config> 3. $resourceName = "my_soap_resource"
$methodName = "myMethod" <config>
<api>
<resources>
<my_soap_resource>
<methods>
<myMethod>

<acl>mysoap/mymethod</acl>
<!-- or: <public>1</public> -->

</myMethod>
</methods>
</my_soap_resource>
</resources>

<acl>
<resources>
<mysoap>
<mymethod>
<title>Trigger some SOAP action or get some data</title>
</mymethod>
</mysoap>
</resources>
</acl>
</api>
</config> Found in Mage_Api_Model_Server_Handler_Abstract::call() 4. $resourceName = "my_soap_resource"
$methodName = "myMethod" authenticate Method Found in Mage_Api_Model_Server_Handler_Abstract::call() <config>
<api>
<resources>
<my_soap_resource>
<methods>
<myMethod>
<method>myMethodName</method>
</myMethod>
</methods>
</my_soap_resource>
</resources>
</api>
</config> 5. resolve Method Name "myMethod" is mapped to "myMethodName"
$resourceName = "my_soap_resource"
$methodName = "myMethodName" Found in Mage_Api_Model_Server_Handler_Abstract::call() <config>
<api>
<resources>
<my_soap_resource>
<model>MySOAP/api</model>
</my_soap_resource>
</resources>
</api>
</config> 6. instantiate Model $resourceName = "my_soap_resource"
$methodName = "myMethodName" Found in Mage_Api_Model_Server_Handler_Abstract::call() <config>
<api>
<resources>
<my_soap_resource>
<methods>
<myMethod>
<method>myMethodName</method>
<!-- <arguments>array</arguments> -->
</myMethod>
</methods>
</my_soap_resource>
</resources>
</api>
</config> 7. call Method <arguments>array</arguments>
function call with one array parameter
otherwise multiple function arguments <?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
<complexType name="customerCustomerEntity">
<all>
<element name="customer_id" type="xsd:int" minOccurs="0" />
<element name="created_at" type="xsd:string" minOccurs="0" />
<element name="updated_at" type="xsd:string" minOccurs="0" />
<element name="increment_id" type="xsd:string" minOccurs="0" />
<element name="store_id" type="xsd:int" minOccurs="0" />
<element name="website_id" type="xsd:int" minOccurs="0" />
<element name="created_in" type="xsd:string" minOccurs="0" />
<element name="email" type="xsd:string" minOccurs="0" />
<element name="firstname" type="xsd:string" minOccurs="0" />
<element name="lastname" type="xsd:string" minOccurs="0" />
<element name="group_id" type="xsd:int" minOccurs="0" />
<element name="password_hash" type="xsd:string" minOccurs="0" />
</all>
</complexType>
<complexType name="customerCustomerEntityArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="typens:customerCustomerEntity[]" />
</restriction>
</complexContent>
</complexType>
</schema>
</types>
<message name="customerCustomerListRequest">
<part name="sessionId" type="xsd:string" />
<part name="filters" type="typens:filters" />
</message>
<message name="customerCustomerListResponse">
<part name="storeView" type="typens:customerCustomerEntityArray" />
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="customerCustomerList">
<documentation>Retrieve customers</documentation>
<input message="typens:customerCustomerListRequest" />
<output message="typens:customerCustomerListResponse" />
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="customerCustomerList">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
</definitions> etc/wsdl.xml extending the API create Models
API v1 + v2 generate WSDL PHP Classes PHP WSDL Generator WSO2 Web Services Framework for PHP Zend_Soap_AutoDiscover => obsolete => unable to compile under OSX => usable since Zend Framework 1.9.4 remove <?php ?>
remove extends
add API resource prefix to methods
add $sessionId as first parameter to public methods Cleanup PHP Generate WSDL Cleanup WSDL eval($classDefinition);
$wsdl = new Zend_Soap_AutoDiscover(true, 'http://dummy/');
$wsdl->setOperationBodyStyle(array('use' => $this->_soapEncoding, 'namespace' => 'urn:Magento'));
$wsdl->setBindingStyle(array('style' => 'rpc, 'transport' => 'http://schemas.xmlsoap.org/soap/http'));
$wsdl->setClass($className);
return $wsdl->toXml(); eval() API Class
create Zend_Soap_AutoDiscover
set Options
get WSDL insert {{var wsdl.xyz}} placeholders
change xml namespaces to match Magento's wsdl.xml files
add <part name="sessionId" type="xsd:string"/> to request message nodes
add encodingStyle to input/output soap:body nodes etc/api.xml summary API v1 easy to use
easy to extend limited client generation possible with PHP
not WS-I compliant (rpc/encoded obsolete since 2003)
no Java or .NET client code generation
no validation on protocol level pros cons API v2 still rather easy to use with PHP
more protocol level validation complex to extend
not WS-I compliant (rpc/encoded obsolete since 2003)
limited client generation possible, also Java / .NET
only basic validation on protocol level pros cons outlook API v3
document/literal wrapped ? easy to use
WS-I compliant
Java and .NET support
more validation on protocol level
reuse v2 API models and configuration one more wsdl.xml to create and maintain pros cons you Experiences? Requirements? Ideas? Code? Thoughts? Questions? Contact: Vinai Kopp <vinai@netzarbeiter.com> Advertisement: Better Configurable Products Extension:
http://www.extensionprogrammer.com my favorite extension This API v3 has come into existance as the API v2 in WS-I complient mode, which, can be enabled in the system configuration since Magento 1.6
Full transcript