Tips: Magento API – filter and complex filter

When you are querying records in Magento, you can use filter to narrow down the result.

 

The basic filter uses the EQUAL operator and AND operand. For example, you can query products with two basic filters: type=simple AND set=39

Example:

 

      <urn:catalogProductList soapenv:encodingStyle=”https://schemas.xmlsoap.org/soap/encoding/”>

         <sessionId xsi:type=”xsd:string”>c9f1ca71de1da4202c84bf90f6df51cf</sessionId>
         <filters xsi:type=”urn:filters”>
            <filter xsi:type=”urn:associativeArray” soapenc:arrayType=”urn:associativeEntity[]”>
<item>
<key>type</key>
<value>simple</value>
</item>
<item>
<key>set</key>
<value>39</value>
</item>
    </filter>
         </filters>
         <storeView xsi:type=”xsd:string”></storeView>
      </urn:catalogProductList>
Using the complex filter, you can perform a more sophisticated search. For example, you can query customers with two complex filters: store_id=0 AND created_at>2012-05-13 06:11:00
Example:
      <urn:customerCustomerList soapenv:encodingStyle=”https://schemas.xmlsoap.org/soap/encoding/”>
         <sessionId xsi:type=”xsd:string”>c9f1ca71de1da4202c84bf90f6df51cf</sessionId>
         <filters xsi:type=”urn:filters”>

            <complex_filter xsi:type=”urn:complexFilterArray” soapenc:arrayType=”urn:complexFilter[]”>
<item>

<key>store_id</key>
<value>
<key>eq</key>
<value>0</value>
</value>
</item>
<item>

<key>created_at</key>
<value>
<key>gt</key>
<value>2012-05-13 06:11:00</value>
</value>
</item>
    </complex_filter>
         </filters>
      </urn:customerCustomerList>The complex filter also uses the AND operand. However, you can specify your own operator. For example: eq (equals), neq (not equals), gt (greater than), lt (less than), etc.