Categories | Set category

Set Category Endpoint

This document outlines the procedure for making API calls to set category data through https://easycms.fi/public_api/set_category/. Utilize various parameters to customize your data insertion.

SETTER API ENDPOINT FOR DATA INSERTION

Setter API calls are limited and not available for public API calls, these calls are only available for resellers or certain software providers and developers upon request.

Categories Data Insertion

Insert category data effectively using the below API call. Apply the required parameters in the request payload to insert category information.

Endpoint and Method

  • Endpoint: https://easycms.fi/public_api/set_category/
  • Method: POST

Parameters | Payload

To insert category data, the following parameters are required:

  • TOKEN (api_key): Your unique API key for authentication. See How to Create API Credentials for more information.
  • username: Your login username.
  • password: Your login password.
  • account: Your specific account ID.
  • category_name: An object containing the category name in different languages. The languages should be defined as keys with their respective language codes, which can be retrieved from the /get_languages endpoint. This endpoint returns all available languages on the system.
  • image: (optional) A URL or base64 code of the category image. Set to false if no image is to be provided.

Image Parameter

  • image: (optional) This parameter allows you to associate an image with the category. You can pass a URL to an image, a base64-encoded image string, or set this parameter to false if no image is to be included.

Example payload:

{
    "TOKEN": "YOUR_API_KEY",
    "username": "YOUR_USERNAME",
    "password": "YOUR_PASSWORD",
    "account": "YOUR_ACCOUNT_ID",
    "category_name": {
        "en_gb": "CategoryNameInEnglish",
        "fi": "CategoryNameInFinnish",
        "zh": "CategoryNameInChinese",
        "vi": "CategoryNameInVietnamese",
        "fa_ir": "CategoryNameInPersian",
        "es": "CategoryNameInSpanish"
    },
    "image": "https://example.com/image_directory/img.png"
}



Call Examples in Different Languages


curl -X POST 'https://easycms.fi/public_api/set_category' \
-H 'Authorization1: TOKEN' \
-d 'username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&category_name[en_gb]=CategoryNameInEnglish&category_name[fi]=CategoryNameInFinnish&category_name[zh]=CategoryNameInChinese&category_name[vi]=CategoryNameInVietnamese&category_name[fa_ir]=CategoryNameInPersian&category_name[es]=CategoryNameInSpanish&image=https://prolasku.fi/image_directory/img.png'

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://easycms.fi/public_api/set_category",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => http_build_query([
    'username' => 'USERNAME', 
    'password' => 'PASSWORD', 
    'account' => 'ACCOUNT_ID',
    'category_name' => [
        'en_gb' => 'CategoryNameInEnglish',
        'fi' => 'CategoryNameInFinnish',
        'zh' => 'CategoryNameInChinese',
        'vi' => 'CategoryNameInVietnamese',
        'fa_ir' => 'CategoryNameInPersian',
        'es' => 'CategoryNameInSpanish'
    ],
    'image' => 'https://prolasku.fi/image_directory/img.png'
  ]),
  CURLOPT_HTTPHEADER => array("Authorization1: TOKEN"),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

import requests
url = "https://easycms.fi/public_api/set_category"
headers = {"Authorization1": "TOKEN"}
payload = {
    'username': 'USERNAME', 
    'password': 'PASSWORD', 
    'account': 'ACCOUNT_ID',
    'category_name[en_gb]': 'CategoryNameInEnglish',
    'category_name[fi]': 'CategoryNameInFinnish',
    'category_name[zh]': 'CategoryNameInChinese',
    'category_name[vi]': 'CategoryNameInVietnamese',
    'category_name[fa_ir]': 'CategoryNameInPersian',
    'category_name[es]': 'CategoryNameInSpanish',
    'image': 'https://prolasku.fi/image_directory/img.png'
}
response = requests.post(url, headers=headers, data=payload)
print(response.text)

// Java example with manual construction of form data
// This is a simplified example and might need adjustments based on the actual library and requirements
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://easycms.fi/public_api/set_category"))
    .headers("Authorization1", "TOKEN")
    .POST(HttpRequest.BodyPublishers.ofString("username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&category_name[en_gb]=CategoryNameInEnglish&category_name[fi]=CategoryNameInFinnish&category_name[zh]=CategoryNameInChinese&category_name[vi]=CategoryNameInVietnamese&category_name[fa_ir]=CategoryNameInPersian&category_name[es]=CategoryNameInSpanish&image=https://prolasku.fi/image_directory/img.png"))
    .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',
  'category_name[en_gb]': 'CategoryNameInEnglish',
  'category_name[fi]': 'CategoryNameInFinnish',
  'category_name[zh]': 'CategoryNameInChinese',
  'category_name[vi]': 'CategoryNameInVietnamese',
  'category_name[fa_ir]': 'CategoryNameInPersian',
  'category_name[es]': 'CategoryNameInSpanish',
  'image': 'https://prolasku.fi/image_directory/img.png'
}).toString();
const options = {
  hostname: 'prolasku.fi',
  path: '/public_api/set_category',
  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 [categoryData, setCategoryData] = useState('');
  useEffect(() => {
    const fetchData = async () => {
      try {
        const response = await fetch('https://easycms.fi/public_api/set_category', {
          method: 'POST',
          headers: {'Authorization1': 'TOKEN', 'Content-Type': 'application/x-www-form-urlencoded'},
          body: new URLSearchParams({
            username: 'USERNAME', 
            password: 'PASSWORD', 
            account: 'ACCOUNT_ID',
            'category_name[en_gb]': 'CategoryNameInEnglish',
            'category_name[fi]': 'CategoryNameInFinnish',
            'category_name[zh]': 'CategoryNameInChinese',
            'category_name[vi]': 'CategoryNameInVietnamese',
            'category_name[fa_ir]': 'CategoryNameInPersian',
            'category_name[es]': 'CategoryNameInSpanish',
            'image': 'https://prolasku.fi/image_directory/img.png'
          }).toString()
        });
        const data = await response.text();
        setCategoryData(data);
      } catch (error) {
        console.error(error);
      }
    };
    fetchData();
  }, []);
  return (
{categoryData}
); } 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.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("category_name[en_gb]", "CategoryNameInEnglish")
        .add("category_name[fi]", "CategoryNameInFinnish")
        .add("category_name[zh]", "CategoryNameInChinese")
        .add("category_name[vi]", "CategoryNameInVietnamese")
        .add("category_name[fa_ir]", "CategoryNameInPersian")
        .add("category_name[es]", "CategoryNameInSpanish")
        .add("image", "https://prolasku.fi/image_directory/img.png")
        .build()

    val request = Request.Builder()
        .url("https://easycms.fi/public_api/set_category")
        .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("category_name[en_gb]", "CategoryNameInEnglish"),
            new KeyValuePair("category_name[fi]", "CategoryNameInFinnish"),
            new KeyValuePair("category_name[zh]", "CategoryNameInChinese"),
            new KeyValuePair("category_name[vi]", "CategoryNameInVietnamese"),
            new KeyValuePair("category_name[fa_ir]", "CategoryNameInPersian"),
            new KeyValuePair("category_name[es]", "CategoryNameInSpanish"),
            new KeyValuePair("image", "https://prolasku.fi/image_directory/img.png")
        });
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("Authorization1", token);
            var response = await httpClient.PostAsync("https://easycms.fi/public_api/set_category", content);
            if (response.IsSuccessStatusCode)
            {
                var responseData = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseData);
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}");
            }
        }
    }
}




Handling Endpoint Results

When you make a request to the endpoint, you receive a JSON response containing various keys and values. Here's an explanation of the response keys and their meanings:


- `cid`: Category ID - A unique identifier for the category.
- `category_name`: Category Name - Represents the name of the category in different languages.
  - `en_gb`: Category name in English (Great Britain).
  - `fi`: Category name in Finnish.
  - Other language codes as per the /get_languages endpoint.

These key-value pairs provide detailed information about the categories, facilitating various applications in your system.
    

{
    "OUTPUT": {
        "0": {
            "cid": "123",
            "visible": "1",
            "parent_id": 0,
            "category_name": {
                "en_gb": "CategoryName_in_en_gb_language",
                "fi": "CategoryName_in_fi_language"
                // Additional languages as needed
            }
        },
        "response_type": "success",
        "message": "Data inserted successfully"
    }
}
    

Error Handling

Here are the possible error messages and their meanings:

  • UN-AUTHORIZED - _user_name_password_is_set_but_wrong_value!: Incorrect username or password.
  • this_account_does_not_exist_or_your_credentials_do_not_match_this_account: The account doesn't exist or mismatched credentials.
  • UN-AUTHORIZED - header is set but the header value is not correct!: Incorrect authorization header value.
  • Maximum query size is 1 rows per query: Exceeded maximum limit of 1 rows per query.