Get a server's history
const url = 'https://app.tunnelhq.com/api/v1/hosts/hst_7/history?metric=cpu&range=1h&country=IR';const options = {method: 'GET', headers: {'X-Project-Id': 'prj_12', 'X-API-Key': '<X-API-Key>'}};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request GET \ --url 'https://app.tunnelhq.com/api/v1/hosts/hst_7/history?metric=cpu&range=1h&country=IR' \ --header 'X-API-Key: <X-API-Key>' \ --header 'X-Project-Id: prj_12'One reading over time, from the server’s history: a point every 5 minutes, kept 7 days. Any role in the project can call it.
With metric=users and country, the users from one country. A point with under 11 users from it is null,
never a number, so no one can be picked out. “Other”, every country under 11, has no history. A server with no
VPN services answers points: null, has_vpn_services: false, and a note.
metric=users on a server that counts no users now adds users_counted: false, users_off_by and a note.
Any points are from before it stopped counting.
Need an API key? See Getting an API key.
Authorizations
Section titled “Authorizations”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “Path Parameters”The server, as hst_7 or 7.
Example
hst_7Header Parameters
Section titled “Header Parameters”The project, as prj_12 or 12. A workspace key can only reach its own workspace’s projects.
Example
prj_12Query Parameters
Section titled “Query Parameters”packet_drops counts tunnel interfaces; nic_drops is what the network card dropped, which is the drop figure for a server that runs only proxies.
With metric=users: one country’s users, as a two letter code.
Example
IRResponses
Section titled “ Responses ”The points.
object
Only with country: the country asked for.
Only with country: a point below this is null.
null only when country is asked of a server with no VPN services.
object
Only when country is asked of a server with no VPN services.
Only when there are no points to show.
Example
{ "unit": "%", "under": 11, "has_vpn_services": false}Headers
Section titled “Headers”Requests the workspace’s plan allows per minute.
Requests left in the current minute.
Unix time, in seconds, when the current minute ends.
The metric, range or country isn’t one it takes.
object
The HTTP status, repeated.
What went wrong.
More detail, on some errors.
Seconds to wait, on the 429 for wrong keys.
Examples
{ "error": true, "code": 400, "message": "range must be 1h, 6h, 24h or 7d."}{ "error": true, "code": 400, "message": "country must be a two letter country code, such as IR."}{ "error": true, "code": 400, "message": "Other is every country with fewer than 11 users. It has no history, so no one can be picked out."}{ "error": true, "code": 400, "message": "country goes with metric=users."}The API key is missing, wrong, expired, switched off, or no longer valid.
object
The HTTP status, repeated.
What went wrong.
More detail, on some errors.
Seconds to wait, on the 429 for wrong keys.
Examples
{ "error": true, "code": 401, "message": "API key is required. Provide X-API-Key header or Authorization: Bearer <key>"}{ "error": true, "code": 401, "message": "Invalid or expired API key"}{ "error": true, "code": 401, "message": "API key has expired"}{ "error": true, "code": 401, "message": "API key owner account is inactive"}{ "error": true, "code": 401, "message": "This API key's workspace access has been removed"}The project has no server with this ID, or the project doesn’t exist.
object
The HTTP status, repeated.
What went wrong.
More detail, on some errors.
Seconds to wait, on the 429 for wrong keys.
Examples
{ "error": true, "code": 404, "message": "No such server in this project."}{ "error": true, "code": 404, "message": "Project not found"}A usage limit was reached, or this IP address made too many requests with a wrong key.
Usage limits are per workspace and plan: per minute (Retry-After: 60), per day
(Retry-After: 3600), and per month (no Retry-After). They use their own body shape.
An IP address may send 10 wrong keys a minute; one more is allowed every 6 seconds. While
that allowance is used up, every request from the address is refused, even one with a
valid key.
object
Seconds to wait. Absent for the monthly limit.
object
The HTTP status, repeated.
What went wrong.
More detail, on some errors.
Seconds to wait, on the 429 for wrong keys.
Examples
{ "error": "Rate limit exceeded", "message": "Per-minute limit of 60 requests exceeded", "retry_after": 60}{ "error": "Daily limit exceeded", "message": "Daily limit of 25000 requests exceeded", "retry_after": 3600}{ "error": "Monthly limit exceeded", "message": "Monthly limit of 250000 requests exceeded"}{ "error": true, "code": 429, "message": "Too many failed API key attempts from this address. Wait a few seconds and try again.", "retry_after": 6}Headers
Section titled “Headers”Seconds to wait. 60 for the per-minute limit, 3600 for the daily limit, 6 after wrong keys. Absent for the monthly limit.
Something failed on TunnelHQ’s side.
object
The HTTP status, repeated.
What went wrong.
More detail, on some errors.
Seconds to wait, on the 429 for wrong keys.
Example
{ "error": true, "code": 500, "message": "Internal server error"}