How toWeb Service Developer Guide

Web Service Developer Guide

Sana Commerce 9.0
Your connector

Filtering

For the most of the methods available in Sana Commerce web service the format of the request is quite simple. Several methods still require more detailed explanation of the request formats because of their comparatively high complexity.
This is the list of methods for which the request format is additionally described below:
 
catalog/productsbycategory/{categoryId}
catalog/productsbyloadoptions
catalog/productsbyproductset/{productsetId}
catalog/search/{keywords}
 
Each of these four methods retrieves the list of products and therefore accepts the same request, which looks the following way:

XML

<ProductListLoadOptions xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
 <Filter>
  <fields>
   <dictionary>
    <FieldCriteriaItem>
     <Key>Id</Key>
      <Value>
       <Field>Id</Field>
       <Options>
        <Criterion i:type="BetweenCriterion">
         <HighValue i:type="a:int" xmlns="http://schemas.datacontract.org/2004/07/Sana.Filtering" xmlns:a="http://www.w3.org/2001/XMLSchema">10</HighValue>
          <LowValue i:type="a:int" xmlns="http://schemas.datacontract.org/2004/07/Sana.Filtering" xmlns:a="http://www.w3.org/2001/XMLSchema">1</LowValue>
        </Criterion>
        <Criterion i:type="ContainsCriterion">
          <Value i:type="a:int" xmlns:a="http://www.w3.org/2001/XMLSchema">1</Value>
          <Not>false</Not>
        </Criterion>
        <Criterion i:type="LessCriterion">
          <Value i:type="a:int" xmlns:a="http://www.w3.org/2001/XMLSchema">1</Value>
          <StrictLess>false</StrictLess>
        </Criterion>
       </Options>
      </Value>
        </FieldCriteriaItem>
        <FieldCriteriaItem>
          <Key>Title</Key>
          <Value>
            <Field>Title</Field>
            <Options>
              <Criterion i:type="GreaterCriterion">
                <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">1</Value>
                <StrictGreater>false</StrictGreater>
            </Criterion>
            <Criterion i:type="EqualCriterion">
              <Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">1</Value>
              <Not>false</Not>
            </Criterion>
          </Options>
        </Value>
       </FieldCriteriaItem>
      </dictionary>
    </fields>
  </Filter>
  <PageIndex>0</PageIndex>
  <PageSize>10</PageSize>
  <SortAscending>true</SortAscending>
  <SortField>Id</SortField>
  <LoadCalculatedFields>true</LoadCalculatedFields>
  <LoadRelatedProducts>false</LoadRelatedProducts>
  <LoadRelatedSkus>false</LoadRelatedSkus>
  <MultiCurrency>false</MultiCurrency>
  <VisibleOnly>false</VisibleOnly>
</ProductListLoadOptions>

JSON

{
    "Filter":
    {
        "fields":
        {
            "dictionary":
            [{
                "Key":"Id",
                "Value":
                {
                    "Field":"Id",
                    "Options":
                    [{
                        "__type":"BetweenCriterion",
                        "HighValue":10,
                        "LowValue":1
                    },
                    {
                        "__type":"ContainsCriterion",
                        "Value":1,
                        "Not":false
                    },
                    {
                        "__type":"LessCriterion",
                        "Value":1,
                        "StrictLess":false
                    }]
                }
            },
            {
                "Key":"Title",
                "Value":
                {
                    "Field":"Title",
                    "Options":
                    [{
                        "__type":"GreaterCriterion",
                        "Value":1,
                        "StrictGreater":false
                    },
                    {
                        "__type":"EqualCriterion",
                        "Value":1,
                        "Not":false
                    }]
                }
            }]
        }
    },
    "PageIndex":0,
    "PageSize":10,
    "SortAscending":true,
    "SortField":"Id",
    "LoadCalculatedFields":true,
    "LoadRelatedProducts":false,
    "LoadRelatedSkus":false,
    "MultiCurrency":false,
    "VisibleOnly":false
}

In the request above a ProductListLoadOptions object is passed, which contains a Filter property among other fields. The Filter property allows to specifying a filter which will be applied to the resulting list of products, returned by any of the four methods mentioned above.
 
If you do not need any filter to be applied, the Filter node in the request should not be present. The example of the request without a filter:

XML JSON
<ProductListLoadOptions xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <PageIndex>0</PageIndex>
  <PageSize>10</PageSize>
  <SortAscending>true</SortAscending>
  <SortField>Id</SortField>
  <LoadCalculatedFields>true</LoadCalculatedFields>
  <LoadRelatedProducts>false</LoadRelatedProducts>
  <LoadRelatedSkus>false</LoadRelatedSkus>
  <MultiCurrency>false</MultiCurrency>
  <VisibleOnly>false</VisibleOnly>
</ProductListLoadOptions>
{
  "PageIndex":0,
  "PageSize":10,
  "SortAscending":true,
  "SortField":"Id",
  "LoadCalculatedFields":true,
  "LoadRelatedProducts":false,
  "LoadRelatedSkus":false,
  "MultiCurrency":false,
  "VisibleOnly":false
}

If an empty Filter node is present, then the web service will fail and the exception occur:

XML JSON
<!-- Error: the Filter node is present but is empty -->
<ProductListLoadOptions xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Filter/> 
  <PageIndex>0</PageIndex>
  <PageSize>10</PageSize>
  <SortAscending>true</SortAscending>
  <SortField>Id</SortField>
  <LoadCalculatedFields>true</LoadCalculatedFields>
  <LoadRelatedProducts>false</LoadRelatedProducts>
  <LoadRelatedSkus>false</LoadRelatedSkus>
  <MultiCurrency>false</MultiCurrency>
  <VisibleOnly>false</VisibleOnly>
</ProductListLoadOptions>
/* Error: the Filter node is present but is empty */
{
  "Filter":{},
  "PageIndex":0,
  "PageSize":10,
  "SortAscending":true,
  "SortField":"Id",
  "LoadCalculatedFields":true,
  "LoadRelatedProducts":false,
  "LoadRelatedSkus":false,
  "MultiCurrency":false,
  "VisibleOnly":false
}

In order to filter the product list which has been retrieved, a Filter node with the specified filter criteria should be added to the request. Multiple filter criteria can be specified, for example conditions, for multiple product fields.

How toWeb Service Developer Guide