---
title: "Preview command encoder"
method: POST
path: "/api/v2/devices/{id}/commands/preview-encoder"
tags: ["Commands"]
---

# Preview command encoder

`POST /api/v2/devices/{id}/commands/preview-encoder`

## Request

- Base URL: `https://api.kiloiot.io`
- URL: `https://api.kiloiot.io/api/v2/devices/{id}/commands/preview-encoder`
- Auth: API key in header `X-API-Key` and API key in header `X-Organization-Id`

Run a custom JavaScript encoder against concrete params in a sandbox (no side effects). Returns the rendered downlink bytes (hex / base64) or a structured encoder error. The HTTP status stays 200 even when the encoder itself fails (see the `error` field).

**Required scope:** `commands:write`

## Path parameters

- `id` string, required

## Request body

- object
  - `organizationId` string, required: Organization ID
  - `customEncoder` string, required: JavaScript encoder source to run in the sandbox.
  - `encodedParamsTemplate` object: Optional template rendered into encoder input.
  - `params` object: Concrete parameter values supplied to the encoder.
  - `fPort` integer

## Response `200`

Encoder preview result. HTTP stays 200 even when the encoder fails (inspect the `error` field).

- object
  - `output` object, nullable
    - `bytes` integer[]
    - `bytesHex` string
    - `bytesBase64` string
  - `logs` string[]
  - `executionTimeMs` number
  - `error` object, nullable
    - `code` string
    - `message` string
    - `lineNumber` integer

## Other responses

- `401`: Missing or invalid API key
- `403`: Insufficient permissions (missing required scope)

---

[API](https://skmtc.dev/kiloiot/apis/kiloiot-public-api.md) · [All operations](https://skmtc.dev/kiloiot/apis/kiloiot-public-api/llms.txt) · [OpenAPI document](https://skmtc.dev/kiloiot/apis/kiloiot-public-api/revisions/faf39bde186c?raw)
