首页 > 解决方案 > 使用 Zeep 过滤 Magento SOAP 请求

问题描述

我正在努力从 Python 2.7 向 Magento 的 SOAP 服务发送过滤器。我正在尝试使用 Zeep 包来调用 SOAP 服务。发送一个空列表作为第二个参数可以很好地返回所有数据。但是,当我在第二个参数中设置过滤器时,它会被忽略,我仍然会得到所有数据。提前致谢!

from zeep import Client

client = Client('https://mywebsite.com/api/v2_soap/index/?wsdl=1')

token = client.service.login('myusername', 'mypassword')

# This works fine, returns all of the customers
customer_list = client.service.customerCustomerList(token, [])

# This still returns all of the customers and ignores the filter
filter = [{'created_at': {'from': '2018-07-01 00:00:00'}}]
customer_list_filtered = client.service.customerCustomerList(token, filter)

我不确定它是否相关,但我收到了这些警告。

C:\Users\some_path_to_python\lib\site-packages\zeep\wsdl\wsdl.py:335: UserWarning: The wsdl:message for u'{urn:Magento}channelintegrationOrderInfoResponse' contains an invalid part ('result'): invalid xsd type or elements
  warnings.warn(str(exc))
C:\Users\some_path_to_python\lib\site-packages\zeep\wsdl\definitions.py:130: UserWarning: The wsdl:operation 'channelintegrationOrderInfo' was not found in the wsdl:portType u'{urn:Magento}PortType'
  warnings.warn(str(exc))

标签: pythonpython-2.7magentosoapzeep

解决方案


就我而言,我必须正确格式化过滤器。按照文档中的示例 - https://devdocs.magento.com/guides/m1x/api/soap/sales/salesOrder/sales_order.list.html#sales_order.list-Examples我必须编写这样的过滤器

filters = [{
    'filter': {
        'complexObjectArray': [{
            'key': 'status',
            'value': 'pending'
        }]
    },
    'complex_filter': {
        'complexObjectArray': [{
            'key': 'status',
            'value': {
                'key': 'in',
                'value': 'pending,processing'
            }
        }]
    }
}]

因此,换句话说,将所有内容包装在 complexObjectArray 中以使其工作。


推荐阅读