Products | Get Products | Filter By category IDs

API Guide: Filtering Product Data by Category IDs

This guide explains how to use our API to retrieve product data by filtering with one or multiple category IDs, referred to as "cid" in our system.

Understanding Category ID Filtering

The API allows you to filter products based on their associated category IDs. This feature is particularly useful when you want to fetch products belonging to specific categories.

How to Obtain Category IDs

Before filtering products, you need to know the available category IDs. Use the get_categories API endpoint to retrieve a list of all categories along with their IDs.

Multiple Category ID Filtering

The API supports filtering by multiple category IDs in a single request. This allows you to retrieve products that fall under several categories at once.

Sample API Calls in Various Programming Languages

We provide examples in different programming languages to demonstrate how to make the API call for filtering products by category IDs.

Call Examples in Different Languages


curl -X POST 'https://easycms.fi/public_api/get_products' \
-H 'Authorization1: TOKEN' \
-d 'username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&cid[]=117&cid[]=119'

$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', 'cid' => [117, 119]]),
  CURLOPT_HTTPHEADER => array("Authorization1: TOKEN"),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

import requests
url = "https://easycms.fi/public_api/get_products"
headers = {"Authorization1": "TOKEN"}
payload = {'username': 'USERNAME', 'password': 'PASSWORD', 'account': 'ACCOUNT_ID', 'cid': [117, 119]}
response = requests.post(url, headers=headers, json=payload)
print(response.text)

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        HttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost("https://easycms.fi/public_api/get_products");

        // Set headers
        httpPost.addHeader("Authorization1", "TOKEN");
        httpPost.addHeader("Content-Type", "application/json");

        // Set request body
        String json = "{\"username\":\"USERNAME\",\"password\":\"PASSWORD\",\"account\":\"ACCOUNT_ID\",\"cid\":[117,119]}";
        StringEntity entity = new StringEntity(json);
        httpPost.setEntity(entity);

        // Execute the request
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity httpEntity = response.getEntity();

        // Print the response
        String responseBody = EntityUtils.toString(httpEntity);
        System.out.println(responseBody);
    }
}

const https = require('https');
const data = JSON.stringify({
  username: 'USERNAME',
  password: 'PASSWORD',
  account: 'ACCOUNT_ID',
  cid: [117, 119]
});
const options = {
  hostname: 'prolasku.fi',
  path: '/public_api/get_products',
  method: 'POST',
  headers: {
    'Authorization1': 'TOKEN',
    'Content-Type': 'application/json',
    '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 response = await fetch('https://easycms.fi/public_api/get_products', {
          method: 'POST',
          headers: {'Authorization1': 'TOKEN', 'Content-Type': 'application/json'},
          body: JSON.stringify({username: 'USERNAME', password: 'PASSWORD', account: 'ACCOUNT_ID', cid: [117, 119]})
        });
        const data = await response.text();
        setProductData(data);
      } catch (error) {
        console.error(error);
      }
    };
    fetchData();
  }, []);
  return (
{productData}
); } export default App;

// Kotlin example requires using a third-party library like OkHttp for POST requests with a body
// Kotlin Example using OkHttp for POST request
import okhttp3.MediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody

fun main() {
    val client = OkHttpClient()

    val json = "{\"username\":\"USERNAME\",\"password\":\"PASSWORD\",\"account\":\"ACCOUNT_ID\",\"cid\":[117,119]}"
    val requestBody = RequestBody.create(MediaType.get("application/json"), json)

    val request = Request.Builder()
        .url("https://easycms.fi/public_api/get_products")
        .post(requestBody)
        .addHeader("Authorization1", "TOKEN")
        .addHeader("Content-Type", "application/json")
        .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.Text;
using System.Threading.Tasks;
class Program
{
    static async Task Main()
    {
        var token = "TOKEN";
        var json = "{\"username\":\"USERNAME\",\"password\":\"PASSWORD\",\"account\":\"ACCOUNT_ID\",\"cid\":[117,119]}";
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        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}");
            }
        }
    }
}