The Weble Cloud API allows external applications and scripts to interact with Weble gateways remotely through the cloud platform. It uses a two-step authentication process: first authenticate with the cloud to get an access token, then authenticate with a specific gateway (host) to get a session token. Once authenticated, all gateway API endpoints are accessible through the cloud proxy.
This is useful for:
The authentication process has two steps:
POST /api/token with your cloud credentials → returns an access_tokenPOST /api/hosts/<hostId>/api/auth with the gateway credentials → returns a sessionIdEvery subsequent request to /api/hosts/<hostId>/api/... must carry both credentials: the cloud token (Authorization: Bearer <access_token>) and the gateway session cookie (WBLSUPSID=<sessionId>).
Cloud credentials → /api/token → access_token
↓
Gateway credentials → /api/hosts/<id>/api/auth → sessionId
↓
API requests → /api/hosts/<id>/api/<endpoint> (with Bearer token + session cookie)
POST https://<cloud>/api/token
Content-Type: application/json
{
"username": "your_cloud_username",
"password": "your_cloud_password"
}
Response: an access token object. Include it as Authorization: Bearer <access_token> in subsequent requests.
If two-factor authentication is enabled on the cloud account, the first POST /api/token returns HTTP 400 with { "resend": true|false, "message": "..." } and sends a code by e-mail or SMS (resend: false means OTP: use your authenticator app). Send the same request again with the code:
{ "username": "...", "password": "...", "twoFactorAuthentication": "123456" }
For unattended scripts, ask Weble for API client credentials (client_id / client_secret) instead of using a personal account.
The response contains access_token, expire_in (validity in ms, 30 minutes) and expire_on (timestamp in ms). When the token has expired, calls return 401 {"err":"token expired"}: request a new token with /api/token.
| HTTP | Meaning |
|---|---|
400 with message |
Second factor required, or INVALID_CODE |
| 401 | Wrong credentials or expired token |
403 ACCOUNT_EXPIRED |
The cloud account has reached its expiration date |
| 429 | Too many failed attempts from your address: wait a few minutes |
POST https://<cloud>/api/hosts/<hostId>/api/auth
Authorization: Bearer <access_token>
Content-Type: application/json
{
"username": "gateway_username",
"password": "gateway_password"
}
Response: an object with several fields; only sessionId is needed. Use it as a cookie (WBLSUPSID=<sessionId>) for gateway API requests.
Once authenticated, all gateway API endpoints are accessible through the cloud proxy. Every request must carry both credentials, the cloud token and the gateway session cookie:
GET https://<cloud>/api/hosts/<hostId>/api/<endpoint>
Authorization: Bearer <access_token>
Cookie: WBLSUPSID=<sessionId>
For example, to get the list of gateways on a host:
GET https://<cloud>/api/hosts/<hostId>/api/supervision/gateways/getGateways
The following script demonstrates the full authentication flow and a gateway API request:
var cloud = 'wbc.weble.ch'
var proxyUsername = 'YOUR_CLOUD_USERNAME'
var proxyPassword = 'YOUR_CLOUD_PASSWORD'
var host = 'HOST_ID'
var username = 'HOST_USERNAME'
var password = 'HOST_PASSWORD'
var access_token;
var https = require('https')
// Generic HTTPS request helper
function request(options, callback) {
var body = options.data
var finish = false
delete options.data
if (!options.headers) options.headers = {}
if (typeof body == 'object') options.headers['Content-Type'] = 'application/json'
if (access_token) options.headers['Authorization'] = 'Bearer ' + access_token.access_token
function done() {
if (finish) return
finish = true
callback(...arguments)
}
var req = https.request(options, res => {
var chunks = [];
res.on('data', data => chunks.push(data))
res.on('end', () => {
let resBody = Buffer.concat(chunks) + ''
try { resBody = JSON.parse(resBody); } catch (e) {}
done(res.statusCode == 200 ? null : res.statusCode, resBody)
})
})
req.on('error', done);
if (typeof body == 'object') req.write(JSON.stringify(body))
else if (body) req.write(body);
req.end();
}
// Step 1: Get cloud access token
function getToken(username, password, callback) {
request({
host: cloud,
path: '/api/token',
method: 'POST',
data: { username: username, password: password }
}, function(err, result) {
if (err) return callback(err)
access_token = result
callback(null, access_token)
})
}
// Step 2: Get gateway session token
function getGatewayToken(host, username, password, callback) {
request({
host: cloud,
path: '/api/hosts/' + host + '/api/auth',
method: 'POST',
data: { username: username, password: password }
}, function(err, result) {
if (err) return callback(err)
callback(null, result.sessionId)
})
}
// Step 3: Make gateway API requests
function gatewayRequest(host, token, options, callback) {
options.path = '/api/hosts/' + host + '/api' + options.path
request(Object.assign({
host: cloud,
headers: { 'Cookie': 'WBLSUPSID=' + token }
}, options || {}), callback)
}
// Run
getToken(proxyUsername, proxyPassword, function(err) {
if (err) throw 'Unable to get cloud token: ' + err
console.log('Cloud login successful')
getGatewayToken(host, username, password, function(err, token) {
if (err) throw 'Unable to get gateway token: ' + err
console.log('Gateway token received:', token)
// Example: get list of gateways
gatewayRequest(host, token, {
method: 'GET',
path: '/supervision/gateways/getGateways'
}, function(err, result) {
console.log('Gateways:', result)
})
})
})
| Parameter | Description |
|---|---|
cloud |
The Weble Cloud server hostname (e.g. wbc.weble.ch). |
proxyUsername / proxyPassword |
Your Weble Cloud account credentials. |
host |
The Host ID of the gateway you want to access. This can be found in the cloud dashboard. |
username / password |
The local credentials of the gateway (the same credentials used to log into the gateway's web interface directly). |
Gateway calls use the generic dispatcher of the gateway, /peers/{peer}/{module}/{method} (see Peers dispatcher). Through the cloud, /peers becomes /api/hosts/<hostId>/api. Arguments are positional: send them in a JSON array named args. Query-string parameters such as ?id= are ignored.
| Method | Endpoint | Body | Description |
|---|---|---|---|
| GET | /supervision/gateways/getGateways |
– | List all drivers (gateways) of the box. |
| POST | /supervision/gateways/getAddressesByGateway |
{ "args": [<gatewayId>] } |
List the addresses of one driver. |
| POST | /supervision/gateways/getLastValue |
{ "args": [<addressId or name>] } |
Last known value (no request sent to the device). |
| POST | /supervision/gateways/readValue |
{ "args": [<addressId or name>] } |
Read the value from the device. |
| POST | /supervision/gateways/writeValue |
{ "args": [<addressId or name>, <value>] } |
Write a value to an address. |
In the Node.js example, a write becomes:
gatewayRequest(host, token, {
method: 'POST',
path: '/supervision/gateways/writeValue',
data: { args: [1234, 21.5] }
}, callback)
The complete list of modules and methods is in the gateway API reference.
The gateway API itself is documented in Gateway API and Peers dispatcher.
The cloud also has its own REST API (same Authorization: Bearer token). The interactive reference (Swagger) is available at https://<cloud>/api/docs once you are logged in to the cloud portal. Main endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/hosts |
Hosts (gateways and users) visible to your account |
| GET / PATCH | /api/hosts/<hostId> |
Read or update one host |
| GET | /api/hosts/<hostId>/connections |
Connections defined on a host |
| GET | /api/hosts/<hostId>/history |
Connection history of a host |
| GET | /api/dashboards |
Your dashboards |
| GET | /api/groups, /api/groups/root |
Groups and group tree |
| GET | /api/users |
Users visible to your account |
| GET | /api/logger/hosts, /api/logger/query |
Data stored by the cloud logger |