Magento 1.7 soap request using filter and/or complex filter

Magento 1.7 soap request using filter and/or complex filter

August 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 1.7 soap request using filter and/or complex filter

Magento SOAP API: Filtering Orders Using Complex Filters

Magento’s SOAP API allows you to retrieve order data programmatically using filters for better data management. In this post, we’ll explore how to use complex filters in the salesOrderListRequest service.

Understanding the SOAP Request Structure

Here is the basic structure of a Magento 1.7 SOAP request without any parameters:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:salesOrderListRequestParam>
         <sessionId>?</sessionId>
         <filters>
            <!--Optional:-->
            <filter>
               <!--Zero or more repetitions:-->
               <complexObjectArray>
                  <key>?</key>
                  <value>?</value>
               </complexObjectArray>
            </filter>
            <!--Optional:-->
            <complex_filter>
               <!--Zero or more repetitions:-->
               <complexObjectArray>
                  <key>?</key>
                  <value>
                     <key>?</key>
                     <value>?</value>
                  </value>
               </complexObjectArray>
            </complex_filter>
         </filters>
      </urn:salesOrderListRequestParam>
   </soapenv:Body>
</soapenv:Envelope>

Filtering Orders by Customer Last Name

To filter orders by a customer’s last name, you can send a request like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:salesOrderListRequestParam>
         <sessionId>02ec011a4deef70a55104d8b229e0d41</sessionId>
         <filters>
            <!--Optional:-->
            <filter>
               <!--Zero or more repetitions:-->
               <complexObjectArray>
                  <key>customer_lastname</key>
                  <value>cook</value>
               </complexObjectArray>
            </filter>
            <complex_filter/>
         </filters>
      </urn:salesOrderListRequestParam>
   </soapenv:Body>
</soapenv:Envelope>

The response will contain a list of orders for customers with the last name “Cook”.

Filtering Orders by Creation Date Range

Now, let’s try to filter orders created within a specific date range:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns2:salesOrderListRequestParam
            xmlns:ns2="urn:Magento" >
            <sessionId>2b15208c5153189ed7477750c177716c</sessionId>
            <filters>
                <complex_filter>
                    <complexObjectArray>
                        <key>created_at</key>
                        <value>
                            <key>from</key>
                            <value>2012-07-06 12:55:51</value>
                        </value>
                    </complexObjectArray>
                </complex_filter>
            </filters>
        </ns2:salesOrderListRequestParam>
    </soap:Body>
</soap:Envelope>

However, this request triggers an error in the database query. The generated SQL statement contains an invalid field from in the WHERE clause.

The Issue with Complex Filters

The problem lies in how Magento interprets complex filters. When you specify a filter like <key>created_at</key><value><key>from</key><value>[date]</value></value>, Magento incorrectly interprets it as if you’re searching for an empty string value.

To resolve this issue, you need to provide the correct field name in the outer complex_filter element. Here’s how the corrected request should look:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="urn:Magento">
    <soap:Header/>
    <soap:Body>
        <ns1:salesOrderListRequestParam>
            <sessionId>your_session_id_here</sessionId>
            <filters>
                <complex_filter>
                    <complexObjectArray>
                        <key>created_at</key>
                        <value xsi:type="associativeEntity">
                            <key xmlns:ns2="urn:Magento">to</key>
                            <value xmlns:ns2="urn:Magento">[later_date]</value>
                        </value>
                    </complexObjectArray>
                </complex_filter>
            </filters>
        </ns1:salesOrderListRequestParam>
    </soap:Body>
</soap:Envelope>

Replace [later_date] with the desired later date.

Conclusion

When using complex filters in Magento’s SOAP API, it’s crucial to structure your XML request correctly. Always ensure that you’re using the appropriate field names and nesting levels for your filter criteria.

Remember, the key-value pairs within complexObjectArray should match the actual field names in your database table, not arbitrary keys like “from”.

For more detailed information on Magento SOAP API integration and customization, I recommend checking out Laravel Company’s comprehensive guide.

Magento 1 API Orders Customers

Our network