Inventory & Products | Products | Product Data | Get Products | Filters | by Custom WHERE

API Guide: Filtering Products with Custom WHERE Conditions

This document provides the details for making an API call to retrieve product data using custom WHERE conditions.

Get Products with Custom WHERE

This API call fetches product data filtered by custom WHERE conditions. Pass the where[] parameter as an array of conditions for advanced filtering beyond the built-in filter parameters.

Understanding Custom WHERE Conditions

This feature allows you to apply arbitrary WHERE conditions to the product query. Each condition is an array with 2 or 3 elements:

  • 2 elements: [column, value] — uses the default = operator.
  • 3 elements: [column, value, operator] — uses the specified operator.

Supported Operators

Operator Description Example
= Equal to (default) ['prdStatus', 1, '=']
!= Not equal to ['onsale', 0, '!=']
> Greater than ['price', 100, '>']
< Less than ['weight', 5, '<']
>= Greater than or equal ['min_order', 10, '>=']
<= Less than or equal ['stock_alert_qty', 50, '<=']
IN Value in list ['cid', [1, 2, 3], 'IN']
NOT IN Value not in list ['bid', [5, 6], 'NOT IN']
LIKE Pattern match ['prdNumber', '%ABC%', 'LIKE']
NOT LIKE Pattern does not match ['barcode', '%TEST%', 'NOT LIKE']
BETWEEN Range (value is array) ['price', [10, 50], 'BETWEEN']
NOT BETWEEN Outside range ['price', [100, 500], 'NOT BETWEEN']

Important Notes

  • Conditions are applied with AND logic — products must match ALL conditions.
  • Column names can use the prd alias prefix (e.g., prd.price) since the main table is aliased as prd.
  • String values do not need to be manually quoted — the database wrapper handles escaping.
  • This parameter is processed after all built-in filters, so it can override or complement them.

How to Use the Custom WHERE Filter

Pass where[] as an array of condition arrays in your API call.

Use Cases for Custom WHERE Conditions

  • Product Status: Filter by prdStatus, onsale, or deleted status.
  • Weight/Dimension Filtering: Filter products by physical attributes like weight, width, height.
  • Stock Alerts: Find products where stock_alert_qty exceeds a threshold.
  • Product Numbers: Filter by prdNumber using LIKE patterns.
  • Complex Combinations: Apply conditions that aren't covered by built-in filters.

Combining with Other Filters

Custom WHERE conditions can be combined with any other filter parameter. The built-in filters are applied first, then the custom WHERE conditions are applied on top.

Call Examples in Different Languages


# Find products that are on sale and weigh more than 5
curl -X POST 'https://easycms.fi/public_api/get_products' \
-H 'Authorization1: TOKEN' \
-d 'username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&where[0][0]=onsale&where[0][1]=1&where[1][0]=weight&where[1][1]=5&where[1][2]=>'

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://easycms.fi/public_api/get_products",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => http_build_query([
    'username' => 'USERNAME',
    'password' => 'PASSWORD',
    'account' => 'ACCOUNT_ID',
    'where' => [
      ['onsale', 1, '='],           // Products on sale
      ['weight', 5, '>'],           // Weight greater than 5
      ['prdNumber', '%ABC%', 'LIKE'] // Product number contains ABC
    ]
  ]),
  CURLOPT_HTTPHEADER => array("Authorization1: TOKEN"),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

import requests
import json
url = "https://easycms.fi/public_api/get_products"
headers = {"Authorization1": "TOKEN"}
payload = {
    'username': 'USERNAME',
    'password': 'PASSWORD',
    'account': 'ACCOUNT_ID',
    'where': json.dumps([
        ['onsale', 1, '='],
        ['weight', 5, '>']
    ])
}
response = requests.post(url, headers=headers, data=payload)
print(response.text)

HttpClient client = HttpClient.newHttpClient();
// where[0][0]=onsale&where[0][1]=1&where[1][0]=weight&where[1][1]=5&where[1][2]=
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://easycms.fi/public_api/get_products"))
    .headers("Authorization1", "TOKEN")
    .POST(HttpRequest.BodyPublishers.ofString(
        "username=USERNAME&password=PASSWORD&account=ACCOUNT_ID" +
        "&where[0][0]=onsale&where[0][1]=1" +
        "&where[1][0]=weight&where[1][1]=5&where[1][2]=>"
    ))
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

const https = require('https');
const data = new URLSearchParams({ 
  username: 'USERNAME', 
  password: 'PASSWORD', 
  account: 'ACCOUNT_ID',
  'where[0][0]': 'onsale',
  'where[0][1]': '1',
  'where[1][0]': 'weight',
  'where[1][1]': '5',
  'where[1][2]': '>'
}).toString();
const options = {
  hostname: 'prolasku.fi',
  path: '/public_api/get_products',
  method: 'POST',
  headers: {
    'Authorization1': 'TOKEN',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': data.length
  }
};
const req = https.request(options, (res) => {
  let data = '';
  res.on('data', (chunk) => { data += chunk; });
  res.on('end', () => { console.log(data); });
});
req.on('error', (e) => { console.error(e); });
req.write(data);
req.end();

import React, { useEffect, useState } from 'react';
function App() {
  const [productData, setProductData] = useState('');
  useEffect(() => {
    const fetchData = async () => {
      try {
        const params = new URLSearchParams({
          username: 'USERNAME', password: 'PASSWORD', account: 'ACCOUNT_ID'
        });
        // Add custom WHERE conditions
        params.append('where[0][0]', 'onsale');
        params.append('where[0][1]', '1');
        params.append('where[1][0]', 'weight');
        params.append('where[1][1]', '5');
        params.append('where[1][2]', '>');

        const response = await fetch('https://easycms.fi/public_api/get_products', {
          method: 'POST',
          headers: {'Authorization1': 'TOKEN', 'Content-Type': 'application/x-www-form-urlencoded'},
          body: params.toString()
        });
        const data = await response.text();
        setProductData(data);
      } catch (error) {
        console.error(error);
      }
    };
    fetchData();
  }, []);
  return (
{productData}
); } export default App;

// Kotlin Example using OkHttp for POST request
import okhttp3.OkHttpClient
import okhttp3.FormBody
import okhttp3.Request

fun main() {
    val client = OkHttpClient()

    val formBody = FormBody.Builder()
        .add("username", "USERNAME")
        .add("password", "PASSWORD")
        .add("account", "ACCOUNT_ID")
        .add("where[0][0]", "onsale")
        .add("where[0][1]", "1")
        .add("where[1][0]", "weight")
        .add("where[1][1]", "5")
        .add("where[1][2]", ">")
        .build()

    val request = Request.Builder()
        .url("https://easycms.fi/public_api/get_products")
        .post(formBody)
        .addHeader("Authorization1", "TOKEN")
        .build()

    client.newCall(request).execute().use { response ->
        if (!response.isSuccessful) throw IOException("Unexpected code $response")
        println(response.body?.string())
    }
}

using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
    static async Task Main()
    {
        var token = "TOKEN";
        var content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair("username", "USERNAME"),
            new KeyValuePair("password", "PASSWORD"),
            new KeyValuePair("account", "ACCOUNT_ID"),
            new KeyValuePair("where[0][0]", "onsale"),
            new KeyValuePair("where[0][1]", "1"),
            new KeyValuePair("where[1][0]", "weight"),
            new KeyValuePair("where[1][1]", "5"),
            new KeyValuePair("where[1][2]", ">")
        });
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("Authorization1", token);
            var response = await httpClient.PostAsync("https://easycms.fi/public_api/get_products", content);
            if (response.IsSuccessStatusCode)
            {
                var responseData = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseData);
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}");
            }
        }
    }
}