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.20)
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 >= 17.5
- macOS >= 14.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.20
- Released: 2025-12-29
- Added following endpoint functions:
- Get device by ID:
TBUserApiClient/getDeviceById(deviceId:responseHandler:) - Get device info by ID:
TBUserApiClient/getDeviceInfoById(deviceId:responseHandler:) - Save device (to add or update a device):
TBUserApiClient/saveDevice(name:label:deviceId:type:deviceProfileId:tenantId:customerId:accessToken:responseHandler:) - Delete device:
TBUserApiClient/deleteDevice(deviceId:responseHandler:)
- Get device by ID:
- API change: All parameters that previously took an ID as a String have been updated to accept a UUID instead.
📚 For details check my DocC pages: Add, Edit and Delete devices
What’s new in v0.0.16?
- Released: 2025-08-24
- Added
TBUserApiClient/logout()method to request user logout on ThingsBoard server.
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