API reference
Every endpoint speaks JSON, and every address starts at https://xabcloud.com.
Conventions
Every request except GET /api/catalog carries the key, and Content-Type when its body is JSON:
curl https://xabcloud.com/api/instances \
-H "Authorization: Bearer xabc_…" \
-H "Accept-Language: en"Messages and the names of plans and regions are in Chinese unless the request says Accept-Language: en. An error is answered like this, and its message can be passed to the user as it is:
{"error": {"message": "…", "status": 409}}Amounts are in fen, 100 to the yuan.
Plans
| Endpoint | |
|---|---|
GET /api/catalog | The plans on sale (plans), the regions (regions), the system images (images), the longest terms (terms), and grace_days, the days a machine's data is kept after its time ends |
price_month_fen is the price for a month and price_year_fen for a year.
Orders
| Endpoint | |
|---|---|
POST /api/orders | Place an order, for a new machine or a renewal |
GET /api/orders | The account's orders |
GET /api/orders/{out_trade_no} | One order |
GET /api/orders/{out_trade_no}/qr.txt | The payment code drawn in block characters, to print in a terminal as it is; add ?invert=1 for a terminal with a light background |
GET /api/orders/{out_trade_no}/qr.svg | The payment code as an image |
For a new machine:
{"kind": "new", "plan": "starter", "region": "us-west-2",
"period": "month", "quantity": 1, "label": "blog",
"ssh_public_key": "ssh-ed25519 AAAA…"}To renew one:
{"kind": "renew", "instance": "xc-…", "period": "month", "quantity": 1}period is month or year, and quantity is how many months (1–11) or years (1–3). label is an optional name of your own; image may be left out.
In the answer, order.out_trade_no is the order number and order.amount_fen the amount due. payment.code_url is the WeChat Pay link, payment.pay_page a page for the user to open in a browser, and payment.expires_at when the order stops being payable.
order.status | |
|---|---|
pending | Waiting to be paid |
paid | Paid; order.instance is the machine's name |
closed | Expired unpaid; a new order has to be placed |
refunded | Refunded |
Machines
| Endpoint | |
|---|---|
GET /api/instances | Every machine of the account |
GET /api/instances/{name} | One machine and its history, events |
PATCH /api/instances/{name} | Rename it: {"label": "a new name"} |
POST /api/instances/{name}/reboot | Reboot |
PUT /api/instances/{name}/ports | The public ports, replaced as a whole |
DELETE /api/instances/{name}?confirm={name} | Release it; the key must have been allowed to |
After payment instance.status goes through queued, creating and booting, and reaches running in about two minutes. instance.ssh_command is then the command to log in, instance.ipv4 the public address and instance.paid_until when the time ends.
instance.status | |
|---|---|
queued, creating, booting | Being opened |
running | Running |
suspending, suspended | Stopped at the end of its time; its data is kept until instance.release_at |
resuming | Starting again after a renewal |
deleting, deleted | Being released, released |
failed | Something went wrong while opening it; the platform has been told and the paid time is not affected |
Public ports
{"ports": [{"protocol": "tcp", "from": 22, "to": 22},
{"protocol": "tcp", "from": 8000, "to": 8100}]}protocol is tcp or udp. A port that is not in the list is closed; leave out 22 and SSH stops working.
The account
| Endpoint | |
|---|---|
GET /api/me | The account; limits.max_instances is how many machines it may hold, and an order beyond that is answered with 409 |
One machine, start to finish
# 1. the plans
curl https://xabcloud.com/api/catalog -H "Accept-Language: en"
# 2. place the order; the answer has its number
curl https://xabcloud.com/api/orders \
-H "Authorization: Bearer xabc_…" \
-H "Content-Type: application/json" \
-d '{"kind":"new","plan":"starter","region":"us-west-2",
"period":"month","quantity":1,
"ssh_public_key":"ssh-ed25519 AAAA…"}'
# 3. print the payment code and ask the user to scan it with WeChat
curl https://xabcloud.com/api/orders/ORDER/qr.txt \
-H "Authorization: Bearer xabc_…"
# 4. look every few seconds until order.status is paid
curl https://xabcloud.com/api/orders/ORDER \
-H "Authorization: Bearer xabc_…"
# 5. look every few seconds until instance.status is running
curl https://xabcloud.com/api/instances/NAME \
-H "Authorization: Bearer xabc_…"