Inventory & Products | Products | Tags | Set Product Tags

Setting Product Tags Data

This document outlines the procedure for making API calls to create or update product tags data from https://easycms.fi/public_api/set_product_tags/. This endpoint supports both creating new tags and updating existing ones.

Product Tags Data Creation and Update

Use this endpoint to create new product tags or update existing ones. The endpoint automatically determines whether to create or update based on whether a products_tags_id is provided.

Endpoint and Method

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



Parameters | Payload

Each parameter can be used individually or in combination to manage your product tags:

  • TOKEN (api_key): Your unique API key for authentication. How to Create API Credentials.
  • username: Your login username.
  • password: Your login password.
  • account: Your specific account ID.



For CREATE (new tag):

  • products_tags_name: Tag name (required). Can be a string (will default to en_GB) or an object with language codes as keys.
  • visible: Visibility status (optional, default: 1). 1=visible, 0=hidden.
  • parent_id: Parent tag ID (optional, default: 0).
  • default_value: Is this a default tag (optional, default: 0). 1=yes, 0=no.

For UPDATE (existing tag):

  • products_tags_id: Tag ID to update (required for update).
  • products_tags_name: Tag name (optional). Can be a string or an object with language codes.
  • visible: Visibility status (optional). 1=visible, 0=hidden.
  • parent_id: Parent tag ID (optional).
  • default_value: Is this a default tag (optional). 1=yes, 0=no.



Call Examples in Different Languages


# Create a new tag
curl -X POST 'https://easycms.fi/public_api/set_product_tags' \
-H 'Authorization1: TOKEN' \
-H 'Content-Type: application/json' \
-d '{
  "username": "USERNAME",
  "password": "PASSWORD",
  "account": "ACCOUNT_ID",
  "products_tags_name": {"en_GB": "New Tag", "fi": "Uusi Tunniste"},
  "visible": 1
}'

# Update an existing tag
curl -X POST 'https://easycms.fi/public_api/set_product_tags' \
-H 'Authorization1: TOKEN' \
-H 'Content-Type: application/json' \
-d '{
  "username": "USERNAME",
  "password": "PASSWORD",
  "account": "ACCOUNT_ID",
  "products_tags_id": 1,
  "products_tags_name": {"en_GB": "Updated Tag", "fi": "Päivitetty Tunniste"},
  "visible": 1
}'

$curl = curl_init();
$data = [
  'username' => 'USERNAME',
  'password' => 'PASSWORD',
  'account' => 'ACCOUNT_ID',
  'products_tags_name' => ['en_GB' => 'New Tag', 'fi' => 'Uusi Tunniste'],
  'visible' => 1
];
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://easycms.fi/public_api/set_product_tags",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => json_encode($data),
  CURLOPT_HTTPHEADER => array(
    "Authorization1: TOKEN",
    "Content-Type: application/json"
  ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

import requests
import json

url = "https://easycms.fi/public_api/set_product_tags"
headers = {
    "Authorization1": "TOKEN",
    "Content-Type": "application/json"
}
payload = {
    'username': 'USERNAME',
    'password': 'PASSWORD',
    'account': 'ACCOUNT_ID',
    'products_tags_name': {'en_GB': 'New Tag', 'fi': 'Uusi Tunniste'},
    'visible': 1
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)

HttpClient client = HttpClient.newHttpClient();
String jsonBody = "{\"username\":\"USERNAME\",\"password\":\"PASSWORD\",\"account\":\"ACCOUNT_ID\",\"products_tags_name\":{\"en_GB\":\"New Tag\"},\"visible\":1}";
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://easycms.fi/public_api/set_product_tags"))
    .headers("Authorization1", "TOKEN", "Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(jsonBody))
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

const https = require('https');
const data = JSON.stringify({
  username: 'USERNAME',
  password: 'PASSWORD',
  account: 'ACCOUNT_ID',
  products_tags_name: { en_GB: 'New Tag', fi: 'Uusi Tunniste' },
  visible: 1
});
const options = {
  hostname: 'prolasku.fi',
  path: '/public_api/set_product_tags',
  method: 'POST',
  headers: {
    'Authorization1': 'TOKEN',
    'Content-Type': 'application/json',
    'Content-Length': data.length
  }
};
const req = https.request(options, (res) => {
  let responseData = '';
  res.on('data', (chunk) => { responseData += chunk; });
  res.on('end', () => { console.log(responseData); });
});
req.on('error', (e) => { console.error(e); });
req.write(data);
req.end();

import React, { useState } from 'react';
function CreateTag() {
  const [response, setResponse] = useState('');
  const createTag = async () => {
    try {
      const res = await fetch('https://easycms.fi/public_api/set_product_tags', {
        method: 'POST',
        headers: {
          'Authorization1': 'TOKEN',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          username: 'USERNAME',
          password: 'PASSWORD',
          account: 'ACCOUNT_ID',
          products_tags_name: { en_GB: 'New Tag' },
          visible: 1
        })
      });
      const data = await res.json();
      setResponse(JSON.stringify(data, null, 2));
    } catch (error) {
      console.error(error);
    }
  };
  return (
    
{response}
); } export default CreateTag;

// Kotlin Example using OkHttp for POST request with JSON body
import okhttp3.OkHttpClient
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Request

fun main() {
    val client = OkHttpClient()
    val json = """
        {
            "username": "USERNAME",
            "password": "PASSWORD",
            "account": "ACCOUNT_ID",
            "products_tags_name": {"en_GB": "New Tag"},
            "visible": 1
        }
    """.trimIndent()

    val body = json.toRequestBody("application/json".toMediaType())

    val request = Request.Builder()
        .url("https://easycms.fi/public_api/set_product_tags")
        .post(body)
        .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.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var token = "TOKEN";
        var payload = new {
            username = "USERNAME",
            password = "PASSWORD",
            account = "ACCOUNT_ID",
            products_tags_name = new { en_GB = "New Tag" },
            visible = 1
        };
        var json = JsonSerializer.Serialize(payload);
        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/set_product_tags", 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:


#### Create Response:
- `response_type`: Response status - "success" or "error".
- `message`: Status message describing the result.
- `tag`: The created tag object containing all tag data.
  - `products_tags_id`: The ID of the newly created tag.
  - `crproducts_tags_id`: The UUID of the tag.
  - `products_tags_number`: The sequential number of the tag.
  - `products_tags_name`: Object containing tag names in different languages.
  - `visible`: Visibility status.
  - `parent_id`: Parent tag ID.
  - `default_value`: Default tag indicator.
  - `image`: Image URL.
  - `image_name`: Image filename.
- `changes`: Object containing details of what was created.
  - `tag_created`: Object with creation details including IDs.

#### Update Response:
- `response_type`: Response status - "success" or "error".
- `message`: Status message describing the result.
- `tag`: The updated tag object containing all current tag data.
- `changes`: Object containing details of what was updated.
  - `tag`: Object with field names as keys and their updated values.
    

#### Create Response Example:
{
    "OUTPUT": {
        "response_type": "success",
        "message": "Tag created successfully",
        "tag": {
            "products_tags_id": "4",
            "crproducts_tags_id": "550e8400-e29b-41d4-a716-446655440003",
            "products_tags_number": "4",
            "products_tags_name": {
                "en_GB": "New Tag",
                "fi": "Uusi Tunniste"
            },
            "visible": "1",
            "parent_id": "0",
            "default_value": "0",
            "image": null,
            "image_name": null
        }
    },
    "changes": {
        "tag_created": {
            "products_tags_id": 4,
            "crproducts_tags_id": "550e8400-e29b-41d4-a716-446655440003",
            "products_tags_number": 4
        }
    }
}

#### Update Response Example:
{
    "OUTPUT": {
        "response_type": "success",
        "message": "Tag updated successfully",
        "tag": {
            "products_tags_id": "1",
            "crproducts_tags_id": "550e8400-e29b-41d4-a716-446655440000",
            "products_tags_number": "1",
            "products_tags_name": {
                "en_GB": "Updated Tag",
                "fi": "Päivitetty Tunniste"
            },
            "visible": "1",
            "parent_id": "0",
            "default_value": "0",
            "image": null,
            "image_name": null
        }
    },
    "changes": {
        "tag": {
            "products_tags_name": {
                "en_GB": "Updated Tag",
                "fi": "Päivitetty Tunniste"
            },
            "visible": 1
        }
    }
}
    

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.
  • products_tags_name_is_required: The products_tags_name field is required when creating a new tag.
  • tag_not_found: The specified tag ID does not exist.
  • update_failed: Failed to update the tag in the database.
  • create_failed: Failed to create the tag in the database.