TBRESTClientLib – A ThingsBoard API Client written in Swift

Implementation of ThingsBoard’s ReST client API – written in Swift:
🥾 Motivation
When developing IoT and IIoT solutions, having a reliable IoT platform is crucial. For both private projects and at work, I use ThingsBoard (most of the time the Community Edition).
ThingsBoard provides device management, administration, and multiple options for storing and visualizing time-series data from sensors, field devices, machine control systems, and many more.
If you need to manage your IoT devices and access their time-series data through a mobile app, you have to implement ThingsBoard’s REST API (in Swift). That’s exactly what I’ve done with this library – meet TBRESTClientLib.
🛠 Development Status – Available Functions (v0.0.29)
This library is continuously growing but has not yet implemented all API endpoints. Currently supported functionality:
- Login
- Logout
- Read own user profile
- Read customer info
- Read devices and device profiles
- Add, Edit and Delete devices
- Read attributes
- Set / delete attributes
- Read time-series data
- Manipulate / delete time-series data
Please refer to the documentation for further details regarding the development status.
📝 Documentation
💻 Requirements
This library works with and was tested on:
- iOS >= 15.0
- macOS >= 11.0
For compatibility to specific ThingsBoard server versions, refer to ThingsBoard Server Compatibility in this library documentation.
📑 Disclaimer
This library is an independent implementation and is not affiliated with, endorsed by, or officially associated with ThingsBoard Inc. in any way. It is licensed under the MIT License
🕰️ Release history
Client - Version 0.0.29
- Released: 2026-08-12
- Added API key authentication (available since ThingsBoard 4.3): the client can now be initialized with an API key via
TBUserApiClient/init(baseUrlStr:apiKey:apiEndpointVersion:httpSessionHandler:requestTimeout:logger:). NoTBUserApiClient/login()call is required – every request is authenticated with the provided key. Since ThingsBoard 4.3, this is the preferred authentication method over the (deprecated) JWT token mechanism. See Initialization-with-an-API-key.
Client – Version 0.0.26
- Released: 2026-08-11
- Added an async/await API: every request method now exists in an additional async variant with the same name minus the
responseHandlerparameter (e.g.TBUserApiClient/login(),TBUserApiClient/getUser()). - Refer to Release Notes for details.
Client – Version 0.0.24
- Released: 2026-08-11
- Reworked the error type structure — breaking change for implementors matching on
TBHTTPClientRequestError. Refer to Release Notes for details.
Client – Version 0.0.21
- Released: 2026-07-20
- Added following endpoint:
getTenantDevices(pageSize:page:type:textSearch:sortProperty:sortOrder:responseHandler:)
📚 For details check my DocC pages: Get tenant devices and device infos
What’s new in v0.0.13?
- Removed
intValfromMplValueTypeto prevent floating point numbers having a zero as only decimal digit (e.g. 20.0) to be treated as integers. - Values (
AttributesResponseorTimeseriesResponse) now support: Bool, Double, String
What’s new in v0.0.11?
- Released: 2025-06-21
- Both initializers now support an (optional)
loggerparameter which takes anLogger?instance (from OSLog) as an argument for improved logging capabilities
import OSLog
import TBRESTClientLib
let logger = Logger(subsystem: "myApp.TBRESTClientLib", category: "Library")
let myClient = try? TBUserApiClient(baseUrlStr: "https://my-thingsboard-iot-server.com",
username: "MyUsername",
password: "MySuperSecretPassword",
logger: logger)
📚 For details check my DocC pages: ThingsBoard Swift Initialization & Login
What’s new in v0.0.10?
- ✅ Introduced
registerErrorHandler(apiErrorHandler:systemErrorHandler:)for more fine-grained error handling - ✅ Now distinguishes between API errors (e.g. HTTP 500) and system-level errors (e.g. DNS failure)
- ✅ Both handlers are optional and can be registered or updated any time
❌ TBHTTPRequest/registerAppErrorHandler is now deprecated, refer to ThingsBoard Swift Client Initialization