Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors

Request

The Request Connector polls external HTTP(S) API endpoints on a configurable schedule, extracts device data from the responses, and forwards it to ThingsBoard as attributes and telemetry. It can also push data to external HTTP(S) APIs in response to shared attribute updates and RPC commands from ThingsBoard.

To enable this connector, add it to the connectors list in tb_gateway.json — see the General Configuration reference.

The connector reads its settings from a JSON file. Below is a full example:

{
"host": "http://127.0.0.1:5000",
"SSLVerify": true,
"security": {
"type": "oauth2",
"tokenUrl": "http://127.0.0.1:5000/oauth2/token",
"clientId": "client_id",
"clientSecret": "client_secret",
"scope": "read write",
"clientAuthentication": "header",
"tokenPrefix": "Bearer",
"tokenRefreshRatio": 0.75,
"tokenRequestTimeout": 10,
"tokenRetryDelay": 10,
"defaultExpiresIn": 3600
},
"mapping": [
{
"url": "getdata",
"httpMethod": "GET",
Parameter Default Description
host http://127.0.0.1:5000 Base URL of the external HTTP(S) server
SSLVerify true Verify the server’s SSL certificate

Global authorization credentials sent with every request to the external server. Supported types: basic, oauth2, and anonymous.

The connector sends an Authorization: Basic <base64(username:password)> header with every request.

Parameter Default Description
type basic Authorization type
username username Username
password password Password
{
"security": {
"type": "basic",
"username": "username",
"password": "password"
}
}

Since ThingsBoard IoT Gateway version 3.8.3, environment variables can be specified for username and password fields. This allows you to avoid hardcoding sensitive information in the configuration file and provide it securely at runtime.

To use ENV variables for username and password, you can set them in your environment or define them in your docker-compose.yml file.

The following ENV variables are used for Basic authentication configuration:

  • REQUEST_BASIC_USERNAME
  • REQUEST_BASIC_PASSWORD

Note that if you specify environment variables for username and password, the values from the configuration file will be ignored, and the connector will use the values from the environment variables instead.

An array of endpoint configurations. Each entry defines a URL to poll, the HTTP method and headers, how often to poll, and how to convert the response into ThingsBoard device data.

Parameter Default Description
url getdata URL path appended to host for the request
httpMethod GET HTTP method (GET, POST, etc.)
httpHeaders {"ACCEPT": "application/json"} Additional HTTP headers
allowRedirects true Follow HTTP redirects
timeout 0.5 Request timeout in seconds
scanPeriod 5 Polling interval in seconds
data (Optional) Request body. An object is sent as form data (application/x-www-form-urlencoded); a string is sent as is. To send JSON, use a string and add "Content-Type": "application/json" to httpHeaders
dataUnpackExpression (Optional) JSON-path expression that selects the part of the JSON response passed to the converter, for example ${payload}. If not set, the whole response is passed
subRequests (Optional) Additional requests that fetch values for converter keys. See Subsection “subRequests”

Defines how the HTTP response body is converted into ThingsBoard device data.

The default converter. Parses a JSON response body and maps fields to a device name, type, attributes, and telemetry.

Parameter Default Description
type json Converter type
deviceNameJsonExpression SD8500 JSON expression to extract the device name; a plain string is used as-is
deviceTypeJsonExpression SD JSON expression to extract the device type; a plain string is used as-is
timeout 60000 Milliseconds before a “Device Disconnected” event is triggered
attributes[].type string Data type of the attribute value
attributes[].key serialNumber Attribute key name in ThingsBoard
attributes[].value ${serial} JSON-path expression to extract the value from the response
telemetry[].type string / integer Data type of the telemetry value
telemetry[].key Maintainer Telemetry key name in ThingsBoard
telemetry[].value ${Developer} JSON-path expression to extract the value from the response
telemetry[].tsField (Optional) JSON-path expression for a field carrying a datetime string used as the telemetry timestamp
telemetry[].dayfirst false (Optional) Treat the first number in tsField as the day (true) or month (false)
telemetry[].yearfirst false (Optional) Treat the first number in tsField as the year

Full mapping example:

{
"url": "getdata",
"httpMethod": "GET",
"httpHeaders": {
"ACCEPT": "application/json"
},
"allowRedirects": true,
"timeout": 0.5,
"scanPeriod": 5,
"converter": {
"type": "json",
"deviceNameJsonExpression": "SD8500",
"deviceTypeJsonExpression": "SD",
"attributes": [
{
"key": "serialNumber",
"type": "string",
"value": "${serial}"
}
],
"telemetry": [
{
"key": "Maintainer",
"type": "string",
"value": "${Developer}"
},
{
"key": "Pressure",
"type": "integer",
"value": "${press}",
"tsField": "${timestampField}",
"dayfirst": true
}
]
}
}

You can also combine multiple response fields into a single value using expressions:

{ "key": "combine", "type": "string", "value": "${hum}:${temp}" }

Use sub-requests when a value for a converter key is available only from another endpoint. For each item of the response, the connector sends one more request for every key of subRequests that matches an attributes[].key or telemetry[].key of the converter. The result is added to the item before conversion, so the converter reads it like any other field. Sub-requests use the same httpMethod, httpHeaders, data, timeout, and security as the main request.

Parameter Description
subRequests.<key>.url Sub-request URL. A value that starts with http is used as the full URL. Any other value is appended to the full URL of the main request. ${...} placeholders take values from the item, for example ${id}
subRequests.<key>.processingFunction (Optional) Python code that defines process_data(data, key). Without it, the fields of the JSON response are added to the item as is, so the response must be a JSON object

In the example below, the connector gets a list of devices from /devices. For each device, it requests /devices/<id>/hist/values/..., divides the avg value from the response by 1000, and sends the result as the cumPwr time series:

{
"url": "/devices",
"httpMethod": "GET",
"httpHeaders": {
"ACCEPT": "application/json"
},
"allowRedirects": true,
"timeout": 3.0,
"scanPeriod": 1800,
"subRequests": {
"cumPwr": {
"url": "/${id}/hist/values/ActiveEnergy/SUM13/3600?start=RELATIVE_-1HOUR&end=RELATIVE_-1HOUR&online=false&aggregate=false",
"processingFunction": "def process_data(data, key): return {key: float(data[\"values\"][0][\"avg\"])/1000.0}"
}
},
"converter": {
"type": "json",
"deviceNameJsonExpression": "${id}-${type}",
"deviceTypeJsonExpression": "GridVis",
"attributes": [
{
"key": "id",
"type": "int",
"value": "${id}"
}
],
"telemetry": [
{
"key": "cumPwr",
"type": "float",
"value": "${cumPwr}"
}
]
}
}

Optional. When a ThingsBoard shared attribute changes, the gateway sends an HTTP request to an external URL on the device.

Parameter Default Description
httpMethod GET HTTP method for the outgoing request
httpHeaders {"CONTENT-TYPE": "application/json"} Additional HTTP headers
timeout 0.5 Request timeout in seconds
allowRedirects true Follow HTTP redirects
deviceNameFilter SD.* Regex filter on device name
attributeFilter send_data Regex filter on attribute name
requestUrlExpression sensor/${deviceName}/${attributeKey} Expression to build the request path appended to host
requestValueExpression {"${attributeKey}":"${attributeValue}"} Expression to build the request body
"attributeUpdates": [
{
"httpMethod": "POST",
"httpHeaders": {
"CONTENT-TYPE": "application/json"
},
"timeout": 0.5,
"allowRedirects": true,
"deviceNameFilter": "SD.*",
"attributeFilter": "send_data",
"requestUrlExpression": "sensor/${deviceName}/${attributeKey}",
"requestValueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
}
]

Optional. Maps ThingsBoard RPC commands to outgoing HTTP requests sent to the device.

Parameter Default Description
deviceNameFilter .* Regex filter on device name
methodFilter echo Regex filter on RPC method name
requestUrlExpression sensor/${deviceName}/request/${methodName}/${requestId} Expression to build the request path appended to host
responseTimeout 1 Seconds to wait for a response
httpMethod GET HTTP method for the outgoing request
requestValueExpression ${params} Expression to build the request body
responseValueExpression (Optional) Expression that extracts the value to return from a JSON response, for example ${temp}. Without it, the whole response body is returned
timeout 0.5 Request timeout in seconds
httpHeaders {"CONTENT-TYPE": "application/json"} Additional HTTP headers

The gateway always waits for the HTTP response and replies to ThingsBoard: {"result": <response body>} on success or {"error": "<message>"} on failure.

"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "echo",
"requestUrlExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"responseTimeout": 1,
"httpMethod": "GET",
"requestValueExpression": "${params}",
"timeout": 0.5,
"httpHeaders": {
"Content-Type": "application/json"
}
},
{
"deviceNameFilter": ".*",
"methodFilter": "no-reply",
"requestUrlExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"httpMethod": "POST",
"requestValueExpression": "${params.hum}",
"httpHeaders": {
"Content-Type": "application/json"
}
}
]

The connector also has built-in get and set RPC methods that send an HTTP request without configuration. See the Reserved RPC methods guide for details.