Moving from the legacy API¶
This page is for scripts written against the legacy API at cloud.hosthatch.com, which the Legacy API page documents. It covers what happens to your servers when your account moves to the console, how to find the same server in both APIs, and which endpoints and fields of the HostHatch API replace the legacy ones.
Your servers move with your account¶
You don't need to move anything yourself. When you first sign in to the console and create your first project, every server on your account goes into that project. That includes the servers you deployed through the legacy API. Your SSH keys and snapshots go into the same project.
You own that project, so you can order, upgrade and move servers in it. You can move a server to another project you own later. Each project lists only its own servers, so a script that reads all your servers lists each of your projects.
If a server is ever missing from your projects, the project's owner finds it with List servers in no project and adds it with Add a server to the project.
The legacy API after you move¶
Once your account has moved, the legacy API no longer deploys servers or adds SSH keys. Those two calls answer 403. Your legacy tokens still read, power, upgrade and cancel your servers there. Use the HostHatch API for new servers and keys.
The HostHatch API has keys of its own. Create one on your profile page in the console, as Authentication describes. You send it the same way as a legacy token, in an Authorization: Bearer header.
Matching servers¶
Server ids are different in the two APIs. The legacy id is a number, such as 112233, and it is the server's billing service id. The HostHatch API's id is a string, such as "774736".
The legacy id is in billing.service_id when you get a server from the HostHatch API. To map your legacy ids, list each project's servers and get each one.
curl "https://console.hosthatch.com/api/v1/projects/acme/servers/774736/" \
-H "Authorization: Bearer $HOSTHATCH_API_KEY"
The answer, trimmed to the fields that matter here:
{
"id": "774736",
"hostname": "web-01",
"billing": {"service_id": 112233, "status": "Active"}
}
billing is null when the server has no billing service, or when billing couldn't be read just now. Get the server again a little later. If billing is still null, match that server on its primary IPv4 address instead.
You can also match on the primary IPv4 address. The legacy API has it in network.primary_ipaddress, and the HostHatch API has it in ipv4_primary of each server in a list.
SSH key ids are the same in both APIs, because your keys move with your account.
Endpoints¶
Every HostHatch API path is relative to https://console.hosthatch.com/api/v1 and sits under a project, such as /projects/acme/servers/.
| Legacy API | HostHatch API |
|---|---|
GET /api/v1/products |
List products, List images and List locations |
POST /api/v1/deploy |
Order a server |
GET /api/v1/servers |
List servers, in each project |
GET /api/v1/servers/{server} |
Get a server |
GET /api/v1/servers/{server}/status |
status in Get a server |
POST /api/v1/servers/{server}/boot |
Power on |
POST /api/v1/servers/{server}/shutdown |
Power off |
POST /api/v1/servers/{server}/reboot |
Reboot |
PUT /api/v1/servers/{server}/upgrade |
List upgrade options, then Upgrade a server |
POST /api/v1/servers/{server}/cancel |
Cancel a server |
GET /api/v1/keys |
List SSH keys |
GET /api/v1/keys/{key} |
Get an SSH key |
POST /api/v1/keys |
Add an SSH key |
DELETE /api/v1/keys/{key} |
Delete an SSH key |
The legacy shutdown cuts the power at once, which is Power off in the HostHatch API. Shut down asks the operating system to stop instead.
Fields¶
Servers¶
| Legacy field | HostHatch API field |
|---|---|
id |
billing.service_id. The server's own id is id. |
hostname |
hostname |
state, such as Active |
billing.status |
status from /status, such as online |
status, which is running, stopped or suspended |
created |
created_at |
product._id |
Not in the server object. Products have integer ids, from List products. |
product.name |
plan.name, with the plan's size in plan |
product.location |
location.code, the same codes |
product.image |
image.display_name |
product.available_upgrades |
billing.upgradeable_to, as product ids |
network.primary_ipaddress |
The first address in network.ipv4, or ipv4_primary in lists |
billing.billing_cycle |
billing.billing_cycle |
billing.next_due |
billing.next_due_date |
billing.recurring_cost |
billing.recurring_amount, a decimal string such as "12.00" |
billing.currency |
billing.currency |
billing.initial_cost |
Not in the HostHatch API |
Ordering a server¶
Legacy deploy field |
Order a server field |
|---|---|
product, such as nvme-2gb |
product_id, an integer from List products |
location, such as AMS |
location, the same codes |
billing |
billing_cycle |
image |
image, one of the product's images |
hostname |
hostname |
features.ipv6 |
ipv6 |
features.additional-ipv4 |
ipv4_additional |
features.ssh_keys |
ssh_keys |
The legacy answer has the invoice and the server's id at once. The HostHatch API answers 201 with an order. Poll it until it is completed, and its server_id is the new server. Both APIs pay from your account credit when it covers the invoice. Otherwise the order waits in awaiting_payment until the invoice is paid.
Send an Idempotency-Key header with every order. Then a request you repeat after a lost answer can't buy twice. See If you lose the answer.
Upgrades¶
The legacy product becomes product_id, one of the server's upgrade options. upgrade_disk keeps its name. The answer is an order, as for a new server.
Cancelling¶
The legacy immediate: true becomes "when": "immediate", and immediate: false becomes "when": "end_of_term". when is required. reason keeps its name, and is required for end_of_term.
SSH keys¶
The legacy description becomes name, and value becomes public_key. The HostHatch API has no type.
Other differences¶
- Responses. The legacy API wraps every answer in
{"result": "success", "data": ...}. The HostHatch API answers with the resource itself. - Errors. Errors are problem details with a stable
code, instead of{"result": "error", "message": ...}. An invalid field answers400withvalidation_error, where the legacy API answered422. - Power. A power operation, such as a reboot, answers
202with an action. Poll it to learn when it has finished. - Lists. Lists are paginated, 50 to a page by default. See Conventions.
- Paths. Every path ends with a slash, such as
/servers/. - Rate limits. Each key has a budget per minute. See Rate limits.