Skip to content

Add a listener

POST
/api/tenants/{tenant}/listeners
curl --request POST \
--url http://127.0.0.1:9090/api/tenants/acme/listeners \
--header 'Authorization: Basic <credentials>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 0b6f1d3e-2c4a-4f8e-9a1b-7d5c3e2f1a09' \
--header 'X-Request-Id: 4f1c2b0e-8a7d-4c51-9e2f-3a6b8d0c1e7f' \
--data '{ "id": "public", "listen": "0.0.0.0:8080", "type": "http" }'

Adds a listener, and starts it on every instance: an http listener binds listen (IP:port) and devices make HTTP requests to it; an mqtt listener connects to broker and takes the messages devices publish on the topics of its endpoints. Give it an endpoint (POST /api/tenants/{tenant}/endpoints) to route devices to a package. The port of a new http listener is taken before anything is saved, so a port in use refuses the change. A port no listener used before is answered with a Warning header: open it on your load balancer and firewall too. Recorded in the audit trail, the password left out.

tenant
required
string

The tenant’s id.

Example
acme
X-Request-Id
string
<= 128 characters /^[A-Za-z0-9._:-]+$/

An id to follow the request by: answered back in X-Request-Id, and in the log, the audit trail and the events the request causes. 1 to 128 letters, digits, -, _, . or :; anything else is replaced by a new id.

Example
4f1c2b0e-8a7d-4c51-9e2f-3a6b8d0c1e7f
Idempotency-Key
string
>= 1 characters <= 255 characters

Does the request once, however often it is sent with this key, for 24 hours: sent again with the same request, it is answered as it was the first time (Idempotent-Replayed: true); with another, 422; while the first runs still, 409.

Example
0b6f1d3e-2c4a-4f8e-9a1b-7d5c3e2f1a09
Media typeapplication/json

A listener: where devices reach the gateway. An http listener binds an address and devices make requests to it; an mqtt listener connects to a broker and takes what devices publish there.

object
ack_wait_secs

Mqtt: seconds a message may hold back the acknowledgements of those that came after it (acknowledgements go in the order messages came); past that, the listener starts no new message until it is done with. Greater than 0. Default 30.

integer | null format: int64
allow_from

Http: client addresses let in, as addresses or CIDR ranges. Set, every other address is refused (403). Checked before the endpoint’s own.

Array<string>
broker

Mqtt, required: the broker URL, mqtt://host:1883 or mqtts://host:8883 (TLS); the port defaults to 1883 or 8883. No login in the URL.

string | null
deny_from

Http: client addresses refused (403), whatever allow_from says.

Array<string>
id
required

Its id, as endpoints name it: 1 to 64 letters, digits, ‘-’ or ‘_’. It cannot be changed.

string
listen

Http, required: the socket address to bind, IP:port (“0.0.0.0:8080”).

string | null
password

Mqtt: the broker password, with username. Kept in the database, never shown.

string | null
proxy_protocol

Http: every connection starts with a PROXY protocol header (v1 or v2), as a layer 4 load balancer in front sends it, naming the client. A connection without one is closed. The client the header names is the request’s address: X-Forwarded-For is not read. Only for a listener that nothing but that load balancer can reach.

boolean
type
required

How devices reach it: http or mqtt.

string
Allowed values: http mqtt
username

Mqtt: the user name to log in to the broker with.

string | null
window

Mqtt, required: how many messages the broker gives this client at once before it has acknowledged any: the broker’s in-flight window for it (Mosquitto’s max_inflight_messages, 20 unless set; a value above the broker’s means nothing, one below it holds the listener to less). The listener holds no more unacknowledged messages than this, and starts every one it holds at once, so a device that publishes without pause has at most this many waiting. 1 to 65535.

integer | null format: int32
Example
{
"id": "public",
"listen": "0.0.0.0:8080",
"type": "http"
}

Added: as it is now.

Media typeapplication/json

A listener as the admin API shows it: its settings (the password only as whether there is one) and how it is doing on the instance that answers.

object
ack_wait_secs

Mqtt: seconds a message may hold back the acknowledgements of those after it before no new message is started; absent: 30.

integer | null format: int64
address
required

Http: the address bound while it runs (the port it was given when listen asks for port 0), else listen. mqtt: the broker.

string
allow_from

Http: client addresses let in; set, every other address is refused.

Array<string>
broker

Mqtt: the broker it connects to.

string | null
connected_once

Mqtt: whether the listener has connected to its broker since it started on the instance that answers. The broker’s persistent session for a listener (which keeps a clock’s messages while no instance is connected) exists once any instance has connected; until one has, a broker may acknowledge a clock’s publishes with nobody subscribed. Absent for http listeners.

boolean | null
deny_from

Http: client addresses refused, whatever allow_from says.

Array<string>
endpoints
required

The ids of the endpoints on it that the instance that answers serves.

Array<string>
error

Why it is not running (or, for mqtt, not connected); null when nothing is wrong.

string | null
id
required

The listener’s id.

string
listen

Http: the address it is set to bind, IP:port.

string | null
password_set
required

Mqtt: whether a broker password is set. The password is never shown.

boolean
proxy_protocol

Http: connections start with a PROXY protocol header; absent when not.

boolean
running
required

It runs on the instance that answers.

boolean
stopped
required

Stopped by hand: it stays stopped, across restarts too, until started.

boolean
type
required

How devices reach it: http or mqtt.

string
Allowed values: http mqtt
username

Mqtt: the user name it logs in to the broker with.

string | null
window

Mqtt: how many unacknowledged messages its broker gives it at once (the broker’s window).

integer | null format: int32
Example
{
"address": "0.0.0.0:8080",
"endpoints": [],
"error": null,
"id": "public",
"listen": "0.0.0.0:8080",
"password_set": false,
"running": true,
"stopped": false,
"type": "http"
}

The body is not a listener (an unknown field, a missing id or type), or the listener is not valid: an id that is not 1-64 letters, digits, ‘-’ or ‘_’; listen that is not IP:port; a broker URL that is not mqtt:// or mqtts://; http settings on an mqtt listener or the other way round; proxy_protocol while trusted_proxies is empty.

Media typeapplication/json

A refusal, and why.

object
error
required

Why the request was refused, in a sentence.

string
fields

For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.

Array<object>

What is wrong with one field of a request.

object
field
required

The parameter, as the request names it (values.volume for a setting inside values).

string
message
required

What is wrong with it.

string
request_id

The request’s id, as its X-Request-Id header gives it: what to quote when asking what happened to it.

string | null
Example
{
"error": "listener 'public': listen must be IP:port, got '8080': invalid socket address syntax"
}

A login is configured and the request carries neither it nor an API token, or it carries a wrong login (WWW-Authenticate: Basic realm="Hour Advantage", no body). Or the request carries an API token that is not one (revoked, or never made), login or not (WWW-Authenticate: Bearer realm="Hour Advantage", error="invalid_token", the body the API token was refused).

Media typetext/plain
string
Example
the API token was refused
WWW-Authenticate
string

The scheme to answer with: Basic realm="Hour Advantage", or for a refused token Bearer realm="Hour Advantage", error="invalid_token".

The Host header does not name a loopback address while one is required (no login configured, or the API listens on loopback), or the Origin header does not match the Host: {"error": ...} says which. Or no login is configured and the request carries Forwarded, X-Forwarded-For or X-Real-IP (a proxy forwarded it): the plain text body says so. Or an API token asks for a route its scope does not reach: the plain text body says so.

A refusal, and why.

object
error
required

Why the request was refused, in a sentence.

string
fields

For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.

Array<object>

What is wrong with one field of a request.

object
field
required

The parameter, as the request names it (values.volume for a setting inside values).

string
message
required

What is wrong with it.

string
request_id

The request’s id, as its X-Request-Id header gives it: what to quote when asking what happened to it.

string | null
Example
{
"error": "the Host must name this machine (localhost or a loopback address); an API reached by other names needs the admin login"
}

A listener with that id exists, its port is taken, or the settings were changed on another instance at the same moment (send it again).

Media typeapplication/json

A refusal, and why.

object
error
required

Why the request was refused, in a sentence.

string
fields

For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.

Array<object>

What is wrong with one field of a request.

object
field
required

The parameter, as the request names it (values.volume for a setting inside values).

string
message
required

What is wrong with it.

string
request_id

The request’s id, as its X-Request-Id header gives it: what to quote when asking what happened to it.

string | null
Example
{
"error": "listener 'public' already exists"
}

More than 2 admin logins are being checked at once: send the request again after the Retry-After seconds. A request carrying the login that checked out last, or an API token, is not held up.

Media typetext/plain
string
Example
too many logins at once; try again
Retry-After
integer

Seconds to wait: 1.

Something went wrong in the gateway that asking again will not put right by itself; error says what.

Media typeapplication/json

A refusal, and why.

object
error
required

Why the request was refused, in a sentence.

string
fields

For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.

Array<object>

What is wrong with one field of a request.

object
field
required

The parameter, as the request names it (values.volume for a setting inside values).

string
message
required

What is wrong with it.

string
request_id

The request’s id, as its X-Request-Id header gives it: what to quote when asking what happened to it.

string | null
Example
{
"error": "db error: ERROR: permission denied for table settings"
}

The database cannot be used right now (not reachable, too busy, no connection free in time), or the instance is still starting: send the same request again shortly. An API token that cannot be checked for the same reason is answered 503 in plain text (the API token cannot be checked right now; try again shortly).

Media typeapplication/json

A refusal, and why.

object
error
required

Why the request was refused, in a sentence.

string
fields

For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.

Array<object>

What is wrong with one field of a request.

object
field
required

The parameter, as the request names it (values.volume for a setting inside values).

string
message
required

What is wrong with it.

string
request_id

The request’s id, as its X-Request-Id header gives it: what to quote when asking what happened to it.

string | null
Example
{
"error": "the gateway is starting; try again shortly"
}