How toWeb Service Developer Guide

Web Service Developer Guide

Sana Commerce 8.3
Your provider

Specifying Filter Criteria

Filter criteria can be specified inside the FieldCriteria/Value/Options element of the request. One or multiple criteria can be specified.

For example, you need to get all products with a 'Title' field value equals to 'My Product':

XML JSON
<Filter>
 <fields>
  <dictionary>
   <FieldCriteriaItem>
    <Key>Title</Key>
    <Value>
     <Field>Title</Field>
     <Options>
      <Criterion i:type="EqualCriterion">
       <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">My Product</Value>
       <Not>false</Not>
      </Criterion>
     </Options>
    </Value>
   </FieldCriteriaItem>
  </dictionary>
 </fields>
</Filter>
"Filter":
{
   "fields":
   {
     "dictionary":
     [{
        "Key":"Title",
        "Value":
        {
          "Field":"Title",
          "Options":
          [{
             "__type":"EqualCriterion",
             "Value":"My Product",
             "Not":false
     }]
   }
  }]
  }
}

In the example above the FieldCriteria/Value/Options element is filled with the Criterion element. This element describes the filtering condition, which is applied to the 'Title' field of the product.

For more detailed information about the structure of the Criterion element read this chapter.
 
Several filtering conditions can be combined for the same field. To do this several Criterion elements should be added to the same FieldCriteria/Value/Options element, each stands for each filtering condition.

For example, to get products with the 'Title' field equals to either 'My Product' or 'Another Product', you should add two Criterion elements as shown in the example below:

XML JSON
<Filter>
 <fields>
  <dictionary>
   <FieldCriteriaItem>
    <Key>Title</Key>
    <Value>
     <Field>Title</Field>
     <Options>
      <Criterion i:type="EqualCriterion">
       <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">My Product</Value>
       <Not>false</Not>
      </Criterion>
      <Criterion i:type="EqualCriterion">
       <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">Another Product</Value>
       <Not>false</Not>
      </Criterion>
     </Options>
    </Value>
   </FieldCriteriaItem>
  </dictionary>
 </fields>
</Filter>
"Filter":
{
 "fields":
 {
  "dictionary":
  [{
    "Key":"Title",
    "Value":
    {
      "Field":"Title",
      "Options":
      [{
        "__type":"EqualCriterion",
        "Value":"My Product",
        "Not":false
      },
      {
        "__type":"EqualCriterion",
        "Value":"Another Product",
        "Not":false
      }]
    }
   }]
  }
}


All criteria specified for the same field will be combined through the 'OR' operator.

Several filters can be combined for several fields in one request. In the example below the request, which filters the products by the 'Title' field which is equal to either 'My Product' or 'Another Product' is combined with another filter which is applied to the 'Id' field:

XML JSON
<Filter>
 <fields>
  <dictionary>
   <FieldCriteriaItem>
    <Key>Title</Key>
    <Value>
     <Field>Title</Field>
     <Options>
      <Criterion i:type="EqualCriterion">
       <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">My Product</Value>
       <Not>false</Not>
      </Criterion>
      <Criterion i:type="EqualCriterion">
       <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">Another Product</Value>
       <Not>false</Not>
      </Criterion>
     </Options>
    </Value>
   </FieldCriteriaItem>
   <FieldCriteriaItem>
    <Key>Id</Key>
    <Value>
     <Field>Id</Field>
     <Options>
      <Criterion i:type="EqualCriterion">
       <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">1000</Value>
       <Not>false</Not>
      </Criterion>
     </Options>
    </Value>
   </FieldCriteriaItem>
  </dictionary>
 </fields>
</Filter>
"Filter":
{
 "fields":
 {
  "dictionary":
  [{
   "Key":"Title",
   "Value":
   {
    "Field":"Title",
    "Options":
   [{
   "__type":"EqualCriterion",
   "Value":"My Product",
   "Not":false
   },
   {
   "__type":"EqualCriterion",
   "Value":"Another Product",
   "Not":false
    }]
    }
   },
  {
   "Key":"Id",
   "Value":
   {
   "Field":"Id",
   "Options":
   [{
   "__type":"EqualCriterion",
   "Value":"1000",
   "Not":false
    }]
   }
  }]
 }
}


The filters for different fields are combined through the 'AND' operator.
How toWeb Service Developer Guide