Magento SOAP v1 filters filtering (Python Suds)

updated below

Does anyone have an example of proper XML for the Magento SOAP v1 API to do something according to the following lines:

client.call(session_token,'sales_order.list', {'filters':{'order_id':{'eq':12}}}) 

This is an example of python suds call that doesn't work for me. Indeed, any XML example that filters sales_order.list, catalog_product.list or customer.list will do. I am already working on a version of XMLRPC, but with the python SUP and SOAP v1 API, no matter what filter, I get the whole list that is unfiltered as an answer. Here's what the XML looks like now:

 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:Magento" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Header/> <ns1:Body> <ns4:call> <sessionId xsi:type="ns2:string">6634e1bd1004557677222fd81e809884</sessionId> <resourcePath xsi:type="ns2:string">sales_order.list</resourcePath> <args xsi:type="ns0:args"> <filters xsi:type="ns2:filters"> <order_id xsi:type="ns2:order_id"> <eq xsi:type="ns2:string">7</eq> </order_id> </filters> </args> </ns4:call> </ns1:Body> 

Of course, I have already tried a million other options above. I'm just wondering if my calls are correct, and I have a bad circuit, or if the soap server is awkward or what. Thus, if someone has validated XML to try to imitate, this will help a lot.

Thanks!

update:

according to the first answer I received so far, I already tried this format for filters. The documentation for the Magento API, as we know, is different, inconsistent, and incomplete. here is the XML:

 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:Magento" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Header/> <ns1:Body> <ns4:call> <sessionId xsi:type="ns2:string">93c7aaab38adaab5db732b211e5b</sessionId> <resourcePath xsi:type="ns2:string">sales_order.list</resourcePath> <args xsi:type="ns0:args"> <filter xsi:type="ns2:filter"> <value xsi:type="ns2:string">123</value> <key xsi:type="ns2:string">order_id</key> </filter> </args> </ns4:call> </ns1:Body> </SOAP-ENV:Envelope> 

or perhaps:

 <ns1:Body> <ns4:call> <sessionId xsi:type="ns2:string">93c74cb7ef0baaaaab5db732b211e5b</sessionId> <resourcePath xsi:type="ns2:string">sales_order.list</resourcePath> <args xsi:type="ns0:args"> <filter xsi:type="ns2:filter"> <value xsi:type="ns2:value"> <value xsi:type="ns2:string">123</value> <key xsi:type="ns2:string">eq</key> </value> <key xsi:type="ns2:string">order_id</key> </filter> </args> </ns4:call> </ns1:Body> </SOAP-ENV:Envelope> 

which is as follows:

 {'filter':[{'key':'order_id','value':{'key':'eq','value':'123'}}]} 

in python.

And they all return all orders (in the end ...). So, as I said before, if someone can give me some XML to follow, this might be more useful. I'm probably going to start through a Magento source tomorrow and solve my own problem.

+4
source share
3 answers

Well, I had to brush it off (and learn) in my PHP, but I have an answer here if other bad juices appear and you want to use SUDS (or python in general) with Magento.

this xml:

 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body><ns1:call><sessionId xsi:type="xsd:string">bc11488aaae84c841ac237ea7f24ef</sessionId> <resourcePath xsi:type="xsd:string">sales_order.list</resourcePath> <args SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array"> <item xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">order_id</key> <value xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">from</key> <value xsi:type="xsd:string">11</value> </item> <item> <key xsi:type="xsd:string">to</key> <value xsi:type="xsd:string">12</value> </item> </value> </item> </item> </args> </ns1:call> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

created by this php:

 #! /usr/bin/php5 <?php $client = new SoapClient('http://ip.ip.ip.ip/magento/index.php/api/?wsdl', array('trace'=>TRUE)); $session = $client->login('username', 'password'); $params = array(array( 'order_id' => array( 'from' => '10', 'to' => '12'))); $result = $client->call($session, 'sales_order.list', $params); $resultXML = $client->__getLastRequest(); print($resultXML); ?> 

Of course, it turns out that there are some types of SOAP-related coding problems in Magento, in particular, the implementation of the protocol - it seems that it is designed to work with the PHP Soap client, but not with anything else. But this XML dump allowed me to hack and get a SUDS connection from the ground - send me a message if you're interested. Oh, and a hat tip for @alanstorm.

+4
source

You are writing the wrong format array entry for the filter.

I think if this is a solution for php.

 $params = array(array( 'filter' => array( array( 'key' => 'status', 'value' => 'pending' ), array( 'key' => 'created_at', 'value' => '2001-11-25 12:12:07', ) ), 'complex_filter' => array( array( 'key' => 'order_id', 'value' => array( 'key' => 'in', 'value' => '12,23' ), ), array( 'key' => 'protect_code', 'value' => array( 'key' => 'eq', 'value' => 'ebb2a0' ), ), ) )); $result = $client->__call('salesOrderList', $params); 

You can just align it with python.

+1
source

I know this question is about the v1 API, but if you are using v2 you can do this:

PHP:

 $complexFilter = array( 'complex_filter' => array( array( 'key' => 'type', 'value' => array('key' => 'in', 'value' => 'simple,configurable') ) ) ); $result = $client->catalogProductList($session, $complexFilter); 

Python equivalent:

 complex_filter = [{'complex_filter': [{ 'key': 'type', 'value': [{ 'key': 'in', 'value': 'simple,configurable'}] }] }] client.service.catalogProductList(session, complex_filter) 
0
source

Source: https://habr.com/ru/post/1432592/


All Articles