Skip to main content
PATCH
/
v1
/
custom-kpi-datasets
/
{dataset_id}
/
kpis
/
{kpi_id}
Update KPI
const options = {
  method: 'PATCH',
  headers: {
    'x-api-key': '<x-api-key>',
    'x-organization-id': '<x-organization-id>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: '<string>',
    description: '<string>',
    unit: '<string>',
    value_type: '<string>',
    required: true,
    sort_order: 123,
    options: {}
  })
};

fetch('https://api.dcycle.io/v1/custom-kpi-datasets/{dataset_id}/kpis/{kpi_id}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "id": "<string>",
  "dataset_id": "<string>",
  "name": "<string>",
  "description": {},
  "unit": {},
  "value_type": "<string>",
  "required": true,
  "sort_order": 123,
  "options": {},
  "created_at": {},
  "updated_at": {}
}

Update KPI

Update one or more fields of a KPI definition. Only send the fields you want to change.
For select KPIs: when you send options, the array replaces the current options entirely. Include existing option ids to keep them (optionally renaming/reordering); omit an id to delete that option. New options (without id) are created.

Request

Headers

x-api-key
string
required
Your API key for authenticationExample: sk_live_1234567890abcdef
x-organization-id
string
required
Your organization UUIDExample: a8315ef3-dd50-43f8-b7ce-d839e68d51fa

Path Parameters

dataset_id
string
required
UUID of the parent dataset
kpi_id
string
required
UUID of the KPI to update

Body Parameters

All fields are optional — only send what you want to change.
name
string
KPI name (1–255 characters)
description
string
KPI description (max 2000 characters)
unit
string
Measurement unit (max 50 characters)
value_type
string
Answer type: number, text, percentage, date, boolean, select
required
boolean
Whether a response value is mandatory
sort_order
integer
Display order within the dataset (0-based)
options
array[object]
For select KPIs: full replacement array of options (2–100). Each object:
FieldTypeDescription
idstringExisting option UUID to keep (omit for new options)
labelstringOption label (1–255 chars)
sort_orderintegerDisplay order

Response

Returns the updated KPI definition (HTTP 200).
id
string
KPI UUID.
dataset_id
string
Parent dataset UUID.
name
string
KPI display name.
description
string | null
KPI description.
unit
string | null
Measurement unit (e.g. , kWh).
value_type
string
Data type: number, text, percentage, date, boolean, or select.
required
boolean
Whether a response value is mandatory.
sort_order
integer
Display order within the dataset.
options
array[object]
Available choices for select-type KPIs. Each has id, label, and sort_order.
created_at
datetime
Creation timestamp (ISO 8601).
updated_at
string | null
Last update timestamp (ISO 8601).

Example

curl -X PATCH "https://api.dcycle.io/v1/custom-kpi-datasets/${DATASET_ID}/kpis/${KPI_ID}" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{"name": "Total electricity consumed (all sources)", "unit": "MWh"}'

Successful Response

{
  "id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
  "dataset_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "Total electricity consumed (all sources)",
  "description": "Annual electricity consumption across all sources",
  "unit": "MWh",
  "value_type": "number",
  "required": true,
  "sort_order": 0,
  "options": [],
  "created_at": "2025-05-01T09:00:00Z",
  "updated_at": "2025-06-18T15:00:00Z"
}

Common Errors

401 Unauthorized

Cause: Missing or invalid API key
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}

403 Forbidden

Cause: The authenticated user is not a member of the organization
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}

404 Not Found

Cause: KPI not found
{
  "detail": "KPI not found"
}

422 Validation Error

Cause: Empty options array for a select KPI
{
  "detail": [
    {
      "loc": ["body", "options"],
      "msg": "A select KPI needs at least 2 options.",
      "type": "value_error"
    }
  ]
}

Create KPI

Add a new KPI to the dataset

Delete KPI

Remove a KPI definition