Background
I'm trying to create a category through the Magento SOAP API using Savon. Before anyone suggests it, I can't use the Magento SOAP v2 or REST APIs.
This code sets up my client and logs in:
@client = Savon.client(wsdl: "#{EnvConfig.base_url}/api/soap/?wsdl", log_level: :debug, raise_errors: true, pretty_print_xml: true)
response = @client.call(:login, message: {
username: EnvConfig.magento_api_user,
apiKey: EnvConfig.magento_api_key
})
@token = response.to_hash[:login_response][:login_return]
I'm then able to call magentos various methods. To list all of the products, I can call:
@response = @client.call(:call, message: {session: @token, method: 'catalog_product.list'})
This all works properly, so there doesn't seem to be a problem with any of the code above.
The problem
When I call catalog_category.create, I'm getting an error. If I call the method with only the parentID parameter:
@response = @client.call(:call, message: {session: @token, method: 'catalog_category.create', parent_id: 90})
then the following XML is sent by Savon:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typens="urn:Magento" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<typens:call>
<session>6939ace91ba26b1da9a21334d7ef2c13</session>
<method>catalog_category.create</method>
<parentId>90</parentId>
</typens:call>
</env:Body>
</env:Envelope>
This returns the response Savon::SOAPFault: (103) Attribute "name" is required
:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>103</faultcode>
<faultstring>Attribute "name" is required.</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I'd expect this, as the API documentation makes it clear that the following attributes are not optional:
- parentId
- categoryData
- name
- is_active
- available_sort_by
- default_sort_by
- include_in_menu
So If I make a call containing name
:
@response = @client.call(:call, message: {session: @token, method: 'catalog_category.create', parent_id: 90, category_data: {name: 'Fooooo'}})
This XML is sent:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:typens="urn:Magento" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<typens:call>
<session>6939ace91ba26b1da9a21334d7ef2c13</session>
<method>catalog_category.create</method>
<parentId>90</parentId>
<categoryData>
<name>Fooooo</name>
</categoryData>
</typens:call>
</env:Body>
</env:Envelope>
But I get a Savon::SOAPFault: (SOAP-ENV:Client) Error cannot find parameter
error:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Error cannot find parameter</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I've spent quite a long time trying to work this out, and have tried sending the name
parameter without wrapping it in categoryData, as well as other parameters. All return the same error message.
At the very least, it would be good to know which parameter can't be found!
Any help would really be appreciated :)