Inventory & Products | Stock Types | Set Stock Types

Set Stock Types

This endpoint creates new stock types (units of measure) or updates existing ones through https://easycms.fi/public_api/set_stock_types/. Stock types describe how a product is stocked and sold (e.g. piece, kilogram, package).



Endpoint and Method

  • Endpoint: https://easycms.fi/public_api/set_stock_types/
  • Method: POST
  • Content-Type: application/json



Authentication

  • Header: Authorization1: {API_TOKEN}
  • Body parameters: username, password, account



Request Parameters

Creating a stock type (omit stock_type_id)

Parameter Type Required Description
username string Yes API username
password string Yes API password
account string Yes Account domain
stock_type_name string | object Yes Type name. A plain string is stored as en_GB; or pass a {lang: name} object
stock_type_number integer No Sorting number. Defaults to MAX + 1
stock_alert_qty integer No Low-stock alert threshold (default 10)
parent_id integer No Parent stock type ID (default 0)
visible integer No 1 = visible (default), 0 = hidden
default_value integer No 1 marks this as the account's default stock type (clears the flag on all others)

Updating a stock type (include stock_type_id)

Parameter Type Required Description
username string Yes API username
password string Yes API password
account string Yes Account domain
stock_type_id integer Yes Stock type ID to update
stock_type_name string | object No New name (string or {lang: name} object)
stock_type_number integer No New sorting number
stock_alert_qty integer No New alert threshold
parent_id integer No Parent stock type ID
visible integer No 1 = visible, 0 = hidden
default_value integer No 1 marks as default (clears the flag on all others)

Only the fields you provide are updated. cruom_id is reserved for the cash-register sync and is ignored.



Behavior

  • Create: validates the required fields, resolves stock_type_number (MAX+1 when omitted), inserts the stock type, and returns the new stock_type_id.
  • Update: validates that stock_type_id exists, applies only the provided fields, and returns the refreshed row plus a changes summary (old → new per field).
  • Default exclusivity: only one stock type can be the account default. Setting default_value: 1 clears the flag from every other stock type first — the same rule the admin UI applies.
  • Every stock type insert/update writes to the account's activity log automatically.



Response Format

{
    "status": "success",
    "message": "Stock type created successfully",
    "data": {
        "stock_type_id": 9,
        "stock_type": {
            "stock_type_id": "9",
            "cruom_id": null,
            "stock_type_number": "9",
            "stock_type_name": "a:1:{s:5:\"en_GB\";s:4:\"Kilo\";}",
            "stock_alert_qty": "10",
            "parent_id": "0",
            "visible": "1",
            "default_value": "0"
        }
    },
    "changes": {
        "stock_type_created": {
            "stock_type_id": 9,
            "stock_type_number": 9,
            "default_value": 0
        }
    }
}

Update responses carry message: "Stock type updated successfully" and a changes.stock_type object with old/new values per updated field.



Error Responses

HTTP Code Error Code Description
400 MISSING_REQUIRED_FIELDS stock_type_name missing on create
400 NOTHING_TO_UPDATE No valid stock type fields provided on update
404 STOCK_TYPE_NOT_FOUND stock_type_id does not exist
500 CREATE_FAILED / UPDATE_FAILED Database write failed



Call Examples

Create a stock type

curl -X POST "https://easycms.fi/public_api/set_stock_types/" \
  -H "Content-Type: application/json" \
  -H "Authorization1: YOUR_API_TOKEN" \
  -d '{
    "username": "your_username",
    "password": "your_password",
    "account": "your_account",
    "stock_type_name": {"en_GB": "Kilogram", "fi": "Kilogramma"},
    "stock_alert_qty": 5
  }'

Mark a stock type as the account default

curl -X POST "https://easycms.fi/public_api/set_stock_types/" \
  -H "Content-Type: application/json" \
  -H "Authorization1: YOUR_API_TOKEN" \
  -d '{
    "username": "your_username",
    "password": "your_password",
    "account": "your_account",
    "stock_type_id": 9,
    "default_value": 1
  }'