# Broker servers The directory of known broker servers and a check for any address. Used when adding an account. ### Search broker servers `GET /api/v1/servers` Scope: admin. Searches the directory of trade servers whose web terminal host is known: the built-in list plus every one this install has checked. Matches server name, company and host, ignoring case, spaces, hyphens, dots and other punctuation (`black bull`, `blackbull` and `Black-Bull` find the same). Servers this install has checked come first; an empty `q` returns the top of the list. Server names may contain spaces. **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `q` | string | no | Text to match, for example black bull. Empty for the top of the list. | | `limit` | integer | no | Most rows to return, at most 200. (default 20; 1 to 200) | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Matching servers. A JSON array of Server. | Field | Type | Description | |---|---|---| | `server` | string | Trade server name exactly as the broker spells it, for example Pepperstone-Demo. (required) | | `company` | string | Broker company name. (required) | | `host` | string | Host that serves the broker's MT5 web terminal. (required) | | `port` | integer | Port, usually 443. (required) | | `type` | string | Demo or real money server. (required; one of demo, real) | | `build` | integer or null | MT5 web terminal build seen on the host. null until this install has checked it. (required) | | `verified_at` | integer or null | Unix seconds (UTC) when this install last checked the host. null for a built-in entry it has not checked. (required) | | `tls_name` | string or null | For an IP access point: the name sent (SNI) and checked against the certificate while TCP goes to the IP. null for a named host. (required) | | `pin_sha256` | string or null | SHA-256 of the certificate key an admin pinned for this host (64 hex), or null. (required) | | `prop_firm` | boolean | A prop firm's server (from the built-in directory). (required) | Example: ```json [ { "server": "Pepperstone-Demo", "company": "Pepperstone Group Limited", "host": "mt5-demo01.pepperstone.com", "port": 443, "type": "demo", "build": 6090, "verified_at": 1790966779, "tls_name": null, "pin_sha256": null, "prop_firm": false }, { "server": "Pepperstone-MT5-Live01", "company": "Pepperstone Group Limited", "host": "mt5-1.pepperstone.com", "port": 443, "type": "real", "build": null, "verified_at": null, "tls_name": null, "pin_sha256": null, "prop_firm": false } ] ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/servers?q=pepperstone&limit=20" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/servers", headers=auth, params={"q": "pepperstone", "limit": 20}) r.raise_for_status() print(r.json()) ``` ### Check an address `POST /api/v1/servers/check` Scope: admin. Reads the public web terminal page on a host and reports which trade servers it answers for, and remembers them in the directory. Use it before adding an account on a server the directory does not know. Gateways must be on the public internet: a host that resolves to loopback, link-local, private, carrier-grade NAT, multicast or documentation space is 400 (unless the server runs with `TERMLESS_ALLOW_PRIVATE_GATEWAYS=1`). The certificate is always verified: a missing intermediate is fetched from the certificate's own CA Issuers URL (public addresses only) and the chain verified again; `tls_name` checks an IP access point against the name on its certificate; a certificate for another name or from a private CA is refused with 502 `untrusted_certificate` and a `certificate` object (CertificateError) whose `spki_sha256` an admin may pin by checking again with `fingerprint` (audited as `server_trust`); a pinned host that shows another key is 502 `certificate_changed`. A terminal behind a Cloudflare challenge (only browsers get in) is 502 `browser_only`. Any other failure answers one generic 502 `broker_error` (the route is not a port scanner); the reason is in the server log and the audit trail (`server_check`). **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Request body** (ServerCheckRequest) | Field | Type | Description | |---|---|---| | `host` | string | Host name to check. A pasted link works: the scheme, path, query, fragment and any user@ are dropped, and host:port works when port is left out. (required) | | `port` | integer | Port. Defaults to 443. (default 443) | | `tls_name` | string | For an IP access point: the name on its certificate (sent as SNI and checked). Defaults to the directory's for that host. | | `fingerprint` | string | Pin this certificate key for the host: the spki_sha256 a refused check reported (64 hex; sha256: and colons allowed). Only for a host you know is the broker's; audited as server_trust. | Example: ```json { "host": "mt5-demo01.pepperstone.com" } ``` **Response 200**: The host serves an MT5 web terminal. A ServerCheck object. | Field | Type | Description | |---|---|---| | `ok` | boolean | True when the host serves an MT5 web terminal. (required) | | `host` | string | The host that was checked. (required) | | `port` | integer | The port that was checked. (required) | | `company` | string | Broker company name from the terminal page. (required) | | `build` | integer | Web terminal build. (required) | | `servers` | array of object | Trade servers this host answers for. They are saved to the directory. (required; object: server, type) | | `tls_name` | string or null | The TLS name used, for an IP access point. (required) | | `pin_sha256` | string or null | The pinned key the host was checked with, if any. (required) | Example: ```json { "ok": true, "host": "mt5-demo01.pepperstone.com", "port": 443, "company": "Pepperstone Group Limited", "build": 6090, "servers": [ { "server": "Pepperstone-Demo", "type": "demo" } ], "tls_name": null, "pin_sha256": null } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 untrusted_certificate, browser_only`: broker_error (generic), untrusted_certificate or certificate_changed (with the certificate), or browser_only. **curl** ```sh curl -s -X POST "$TERMLESS_URL/api/v1/servers/check" \ -H "Authorization: Bearer $TERMLESS_KEY" \ -H "Content-Type: application/json" \ -d '{"host": "mt5-demo01.pepperstone.com"}' ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.post(f"{base}/servers/check", headers=auth, json={ "host": "mt5-demo01.pepperstone.com" }) r.raise_for_status() print(r.json()) ``` ### Pin a certificate key `POST /api/v1/servers/{server}/trust` Scope: admin. Pins a certificate key for the server's host and port (every directory row on it), for a broker whose certificate cannot be verified (another name, a private CA). The live host is checked with the pin first, so only the key it presents now can be pinned: 502 `certificate_changed` otherwise. Accounts on that gateway log in again with the pin. Audited as `server_trust`. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `server` | string | yes | Trade server name as in the directory (spaces are allowed; encode them). | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Request body** (TrustRequest) | Field | Type | Description | |---|---|---| | `fingerprint` | string | The key to pin: spki_sha256 from a refused check (64 hex; sha256: and colons allowed). (required) | Example: ```json { "fingerprint": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7" } ``` **Response 200**: Pinned. A TrustResult object. | Field | Type | Description | |---|---|---| | `ok` | boolean | True: pinned. (required) | | `server` | string | The server named in the path. (required) | | `host` | string | Its host. (required) | | `port` | integer | Its port. (required) | | `tls_name` | string or null | Its TLS name, if any. (required) | | `pin_sha256` | string | The pinned key. (required) | | `accounts_restarted` | integer | Accounts on that gateway that logged in again with the pin. (required) | | `servers` | array of object | Servers the host's page lists (saved with the pin). (required; object: server, type) | **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 `: certificate_changed (the host shows another key), or another failure reading the host. **curl** ```sh curl -s -X POST "$TERMLESS_URL/api/v1/servers/Alpari-MT5-Demo/trust" \ -H "Authorization: Bearer $TERMLESS_KEY" \ -H "Content-Type: application/json" \ -d '{"fingerprint": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7"}' ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.post(f"{base}/servers/Alpari-MT5-Demo/trust", headers=auth, json={ "fingerprint": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7" }) r.raise_for_status() print(r.json()) ``` ### Remove a pinned key `DELETE /api/v1/servers/{server}/trust` Scope: admin. Removes the pin for the server's host and port; the host is checked the normal way again and its accounts log in again. Audited as `server_trust`. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `server` | string | yes | Trade server name as in the directory (spaces are allowed; encode them). | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 204**: Removed. **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s -X DELETE "$TERMLESS_URL/api/v1/servers/Alpari-MT5-Demo/trust" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.delete(f"{base}/servers/Alpari-MT5-Demo/trust", headers=auth) r.raise_for_status() # 204, no body ```