{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/open-plant-data/json-schema/open-plant-data-internal-data-upsert-schema.json",
  "title": "InternalDataUpsert",
  "description": "Identity is (authenticated company, data_id, internal_id). Omit optional fields to preserve existing values; send the JSON literal null (without quotes) to clear internal_name, price, old_price or product_url to database NULL. New records default omitted fields to null. Unknown fields are rejected. Strings are trimmed and empty strings become null. To change either identity field, delete the old pair and upsert the new pair. SKU comparisons follow the database collation; use consistent casing.",
  "x-generated": "2026-12-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/open-plant-data-openapi.json#/components/schemas/InternalDataUpsert",
  "required": [
    "data_id",
    "internal_id"
  ],
  "properties": {
    "action": {
      "type": "string",
      "default": "upsert",
      "enum": [
        "upsert"
      ]
    },
    "data_id": {
      "description": "Existing OPD plant ID, as returned by GET /api/plants (id). Must be accessible to the company.",
      "type": "integer",
      "maximum": 2147483647,
      "minimum": 1
    },
    "internal_id": {
      "description": "Customer SKU or EAN. Always send as a string to preserve leading zeroes.",
      "type": "string",
      "maxLength": 100,
      "minLength": 1
    },
    "internal_name": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 200
    },
    "price": {
      "description": "Non-negative decimal number or numeric string, up to 11 integer digits and 4 decimal places. Use a decimal point, no currency symbol, comma or exponent. Returned as a string with 4 decimal places. No currency conversion or tax calculation.",
      "nullable": true,
      "oneOf": [
        {
          "type": [
            "number",
            "null"
          ],
          "maximum": 99999999999.9999,
          "minimum": 0
        },
        {
          "type": "string",
          "pattern": "^\\d{1,11}(\\.\\d{1,4})?$"
        }
      ]
    },
    "old_price": {
      "description": "Previous price; same format as price. Send null when a discount expires. It is not cleared automatically.",
      "nullable": true,
      "oneOf": [
        {
          "type": [
            "number",
            "null"
          ],
          "maximum": 99999999999.9999,
          "minimum": 0
        },
        {
          "type": "string",
          "pattern": "^\\d{1,11}(\\.\\d{1,4})?$"
        }
      ]
    },
    "product_url": {
      "description": "Absolute HTTP(S) URL. Send null to unpublish the link while retaining the mapping.",
      "type": [
        "string",
        "null"
      ],
      "format": "uri",
      "maxLength": 200
    }
  },
  "type": "object",
  "additionalProperties": false
}