Skip to main content
POST
/
v1
/
custom-kpi-datasets
/
{dataset_id}
/
kpis
Create KPI
const options = {
  method: 'POST',
  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', 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": {}
}

Create KPI

Add a new KPI (question) definition to a dataset. Each KPI defines what data owners will be asked during campaigns.

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 datasetExample: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

Body Parameters

name
string
required
KPI name (1–255 characters)Example: "Monthly electricity consumption"
description
string
KPI description (max 2000 characters)Example: "Total kWh consumed from all sources"
unit
string
Measurement unit (max 50 characters)Example: "kWh", "m³", "tonnes"
value_type
string
default:"number"
Expected answer type. One of: number, text, percentage, date, boolean, select
required
boolean
default:"true"
Whether a response value is mandatory
sort_order
integer
default:"0"
Display order within the dataset (0-based)
options
array[object]
Required for select type. List of selectable options (2–100). Each object has:
FieldTypeRequiredDescription
labelstringYesOption label (1–255 chars, unique per KPI case-insensitive)
sort_orderintegerNoDisplay order (default 0)
Options are forbidden for non-select types.

Response

Returns the created KPI definition (HTTP 201).
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
Timestamp when the KPI was created
updated_at
datetime | null
Timestamp when the KPI was last updated

Example

curl -X POST "https://api.dcycle.io/v1/custom-kpi-datasets/${DATASET_ID}/kpis" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Monthly electricity consumption",
    "unit": "kWh",
    "value_type": "number",
    "required": true,
    "sort_order": 0
  }'

Successful Response

{
  "id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
  "dataset_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "Monthly electricity consumption",
  "description": null,
  "unit": "kWh",
  "value_type": "number",
  "required": true,
  "sort_order": 0,
  "options": [],
  "created_at": "2025-03-10T14:00:00Z",
  "updated_at": null
}

Select Type Example

curl -X POST "https://api.dcycle.io/v1/custom-kpi-datasets/${DATASET_ID}/kpis" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Primary energy source",
    "value_type": "select",
    "options": [
      {"label": "Grid electricity", "sort_order": 0},
      {"label": "Solar PV", "sort_order": 1},
      {"label": "Natural gas", "sort_order": 2},
      {"label": "Other", "sort_order": 3}
    ]
  }'

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"}

422 Validation Error

Cause: Select KPI missing options
{
  "detail": [
    {
      "loc": ["body", "__root__"],
      "msg": "A select KPI must define options.",
      "type": "value_error"
    }
  ]
}
Cause: Options provided for a non-select type
{
  "detail": [
    {
      "loc": ["body", "__root__"],
      "msg": "Only select-type KPIs can define options.",
      "type": "value_error"
    }
  ]
}

404 Not Found

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

Update KPI

Modify a KPI definition

Delete KPI

Remove a KPI from the dataset