> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Blynk Device Api

> Client-mode REST API connectors for Blynk.Cloud: read and write device datastreams, upload timestamped data, raise events and manage devices, templates, webhooks and automations from MQTT, plus an opt-in webhook receiver

Technical Preview

## Overview

Client-mode REST API connectors for Blynk.Cloud: read and write device datastreams, upload timestamped data, raise events and manage devices, templates, webhooks and automations from MQTT, plus an opt-in webhook receiver.

This is one of the templates in the Blynk REST API app (`blynk`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

> [!NOTE]
>
> Not yet verified against the live vendor API: No Blynk device auth token or OAuth2 client on the factory box; the ready gate needs an authenticated live GET + POST (or broker MQTT round-trip).

## Auth

Device connector: device auth token in the query string token=\{value.json.token} (Blynk has no header form for the Device HTTPS API); suggested secret BLYNK\_DEVICE\_TOKEN. Platform connector: OAuth2 client credentials (Developers > OAuth2) as HTTP Basic \{value.json.basic\_auth} on GetAccessToken / RefreshAccessToken, then Authorization: Bearer \{value.json.access\_token}; suggested secrets BLYNK\_CLIENT\_BASIC, BLYNK\_ACCESS\_TOKEN. Platform API needs a Prototype / Production / Enterprise plan. Never commit real tokens.

## Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Blynk Device Api connector | no |
| `BaseUrl` | string | Blynk Device Api base URL without trailing slash (e.g. [https://fra1.blynk.cloud](https://fra1.blynk.cloud)) | yes |

`BASE_ADDRESS` default: `https://fra1.blynk.cloud`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `IsDeviceConnected` | GET | `/external/api/isHardwareConnected?token={value.json.token}` | `cloud-iot/blynk/connection/get` | `cloud-iot/blynk/connection/get/response` | `token` |
| `GetDatastreamValue` | GET | `/external/api/get?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/datastream/get` | `cloud-iot/blynk/datastream/get/response` | `query`, `token` |
| `GetAllDatastreamValues` | GET | `/external/api/getAll?token={value.json.token}` | `cloud-iot/blynk/datastream/list` | `cloud-iot/blynk/datastream/list/response` | `token` |
| `UpdateDatastreamValue` | GET | `/external/api/update?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/datastream/update` | `cloud-iot/blynk/datastream/update/response` | `query`, `token` |
| `BatchUpdateDatastreams` | GET | `/external/api/batch/update?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/datastream/batch-update` | `cloud-iot/blynk/datastream/batch-update/response` | `query`, `token` |
| `UploadTimestampedData` | POST | `/external/api/batch/update?token={value.json.token}&pin={value.json.pin}` | `cloud-iot/blynk/datastream-history/upload` | `cloud-iot/blynk/datastream-history/upload/response` | `body`, `pin`, `token` |
| `UpdateDatastreamProperty` | GET | `/external/api/update/property?token={value.json.token}&pin={value.json.pin}&{value.json.query}` | `cloud-iot/blynk/datastream-property/update` | `cloud-iot/blynk/datastream-property/update/response` | `pin`, `query`, `token` |
| `LogEvent` | GET | `/external/api/logEvent?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/event/log` | `cloud-iot/blynk/event/log/response` | `query`, `token` |
| `ExportDeviceHistory` | GET | `/external/api/data/get?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/history/export` | `cloud-iot/blynk/history/export/response` | `query`, `token` |
| `GetDeviceMetafield` | GET | `/external/api/device/meta?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/metafield/get` | `cloud-iot/blynk/metafield/get/response` | `query`, `token` |
| `UpdateDeviceMetafield` | GET | `/external/api/device/meta/update?token={value.json.token}&{value.json.query}` | `cloud-iot/blynk/metafield/update` | `cloud-iot/blynk/metafield/update/response` | `query`, `token` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode BLYNK_DEVICE_API"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE BlynkDeviceApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://fra1.blynk.cloud"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT IsDeviceConnected
        WITH SOURCE_TOPIC "cloud-iot/blynk/connection/get"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/connection/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/isHardwareConnected?token={value.json.token}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT GetDatastreamValue
        WITH SOURCE_TOPIC "cloud-iot/blynk/datastream/get"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/datastream/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/get?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT GetAllDatastreamValues
        WITH SOURCE_TOPIC "cloud-iot/blynk/datastream/list"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/datastream/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/getAll?token={value.json.token}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT UpdateDatastreamValue
        WITH SOURCE_TOPIC "cloud-iot/blynk/datastream/update"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/datastream/update/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/update?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT BatchUpdateDatastreams
        WITH SOURCE_TOPIC "cloud-iot/blynk/datastream/batch-update"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/datastream/batch-update/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/batch/update?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT UploadTimestampedData
        WITH SOURCE_TOPIC "cloud-iot/blynk/datastream-history/upload"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/datastream-history/upload/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/external/api/batch/update?token={value.json.token}&pin={value.json.pin}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.body}"
    ADD EVENT UpdateDatastreamProperty
        WITH SOURCE_TOPIC "cloud-iot/blynk/datastream-property/update"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/datastream-property/update/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/update/property?token={value.json.token}&pin={value.json.pin}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT LogEvent
        WITH SOURCE_TOPIC "cloud-iot/blynk/event/log"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/event/log/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/logEvent?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT ExportDeviceHistory
        WITH SOURCE_TOPIC "cloud-iot/blynk/history/export"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/history/export/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/data/get?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT GetDeviceMetafield
        WITH SOURCE_TOPIC "cloud-iot/blynk/metafield/get"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/metafield/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/device/meta?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
    ADD EVENT UpdateDeviceMetafield
        WITH SOURCE_TOPIC "cloud-iot/blynk/metafield/update"
        WITH DESTINATION_TOPIC "cloud-iot/blynk/metafield/update/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/external/api/device/meta/update?token={value.json.token}&{value.json.query}"
        WITH HEADERS
            ADD "Accept" "application/json"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

## Usage example

Call `IsDeviceConnected` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'cloud-iot/blynk/connection/get/response' &
mosquitto_pub -t 'cloud-iot/blynk/connection/get' -m '{"token": "<token>"}'
```

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps catalog](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.