
Magento 1.x – Adding new fields to Magento core API
If you need to change the Magento core API, such as adding new fields, you will need to extend the core WSDL file of the module of your needs.
In the example below, we are going to add a new field in the Mage/Sales API. To do so, we will need to perform the following steps:
- Create a new local extension.
- Add the following files:
app/code/local/Offset101/SalesOrderApi/etc/wsdl.xml
Take care of the core wsdl(app/code/core/Mage/Sales/etc/wsdl.xml), and add your custom field within the corresponding tags.
ie: If we want to add a “custom_sku” in the complex type salesOrderItemEntity, our wsdl will look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?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="salesOrderItemEntity"> <all> <element name="custom_sku" type="xsd:string" minOccurs="0" /> </all> </complexType> </schema> </types> </definitions> |
app/code/local/Offset101/SalesOrderApi/etc/wsi.xml
Take care of the core wsdl(app/code/core/Mage/Sales/etc/wsi.xml), and add your custom field within the corresponding tags.
ie: If we want to add a “custom_sku” in the complex type salesOrderItemEntity, our wsdl will look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="UTF-8"?> <wsdl: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/" name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}"> <wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}"> <xsd:complexType name="salesOrderItemEntity"> <xsd:sequence> <xsd:element name="custom_sku" type="xsd:string" minOccurs="0" /> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> </wsdl:definitions> |
Once the extension was created and both files were added, you can make a try going through:
- SOAP V1: http://magentohost/api/soap/?wsdl (this one is more like RPC, no concrete operations defined in WSDL, just call)
- SOAP V2: http://magentohost/api/v2_soap?wsdl=1 . For strongly-typed languages use this one and remember to enable WS-I compliance mode on Magento side: Services > Magento Core API > WS-I Compliance to Yes.