API reference
All methods of the Center JSON-RPC API by category. Each method page has a curl request example, the required privilege, parameters, response and errors. How to sign in to the API, pass the session and get the result of a long operation — How to call the API.
Each method has a label under its name. Synchronous methods are called at /.req/: the result comes in the same HTTP response. Asynchronous methods may take a long time: call them at /.async/.req/, Center responds immediately with code 999, and you get the result of the operation with the task method. Which role allows which methods — Roles and privileges.
Description of all methods in OpenAPI format — for generating clients and validating requests: openapi.json.
How to call the API
The Center API is JSON-RPC 2.0 over HTTPS. This section describes how to connect your own script, scheduler or portal to Center.
Before you begin
- You have a Center account for the integration — Create a user and set a password. The API checks permissions the same way as the web interface: the account role must allow the methods you need — Assign a role.
- The account password does not require a change: while the password is temporary, the API allows only a password change — Sign in to the web interface.
- If the account may sign in only from certain addresses or virtual hosts, the integration machine is on the list and connects to the cluster by an allowed name — Restrict sign-in by addresses (CIDR) and virtual hosts.
- You know the address of the cluster web interface, for example
https://203.0.113.10, and the integration machine can reach it over HTTPS. The API responds at the same address, at the path/.api/V4/. curlandjqare installed: the examples use them.
Request and response format
Each call is a POST request with a JSON-RPC 2.0 body:
{"jsonrpc": "2.0", "id": "9d3c2b1a-4e5f-4a6b-8c7d-0e1f2a3b4c5d", "method": "vdc-list", "params": {}}
id— a UUID in lowercase letters, new for each request.uuidgengenerates it; on macOS, useuuidgen | tr A-F a-f.method— lowercase Latin letters, digits,-and_, up to 64 characters.- The body is at most 65 535 bytes.
Center responds with HTTP 200. The body contains either result with code 1 and the data in data, or error with code and message. A method error is also returned with HTTP 200, so check the body. HTTP 503 with the code -10503 means that the cluster is overloaded: retry the request later.
1. Sign in and save the session
-
Send the
authmethod with the account name and password:API=https://203.0.113.10/.api/V4AUTH=$(curl -sS "$API/.req/" -H 'Content-Type: application/json' \-d '{"jsonrpc":"2.0","id":"3f6c1a52-8d0e-4b7a-9c21-5e4f0a7b9d13","method":"auth","params":{"username":"integration","password":"Example-Passw0rd"}}')echo "$AUTH" | jq '.result' -
Make sure that
result.codeis 1 andresult.data.messageisauthenticated. Code 2 andmust change passwordmean a temporary session: it is valid for 5 minutes and can be used only to change the password. Change the password in the web interface and sign in again. -
Save the session as
APIEndpoint00=followed by the value ofresult.data.cookie.APIEndpoint00. In this form, it is passed in the header:SESSION="APIEndpoint00=$(echo "$AUTH" | jq -r '.result.data.cookie.APIEndpoint00')"
The session stays valid while it is in use. If there are no requests for 10 hours, Center closes the session, and you need to sign in again.
2. Call a method
-
Pass the session in the
X-Session-Authheader and call a method, for example, the one that lists virtual data centers (VDCs):curl -sS "$API/.req/" -H 'Content-Type: application/json' -H "X-Session-Auth: $SESSION" \-d '{"jsonrpc":"2.0","id":"8b2d4e61-0f3a-4c59-a7e8-1d6b3c9f2a40","method":"vdc-list","params":{}}'The cluster does not accept the session in the
Cookieheader: the response is-14777 Not authenticated. -
Read the response:
result.codeis 1, andresult.datacontains the list of VDCs available to the account.
A synchronous request waits up to 45 seconds for a response. After that, it returns the error -10500 Request timed out, although the operation may continue. Call long operations asynchronously.
3. Start a long operation and get its outcome
-
Send a request to the
/.async/.req/address, for example, to start the virtual machine (VM) with ID 42:curl -sS "$API/.async/.req/" -H 'Content-Type: application/json' -H "X-Session-Auth: $SESSION" \-d '{"jsonrpc":"2.0","id":"c41e7f20-5b6a-4d8c-9e0f-2a3b4c5d6e7f","method":"vms-start","params":{"id":42}}'Center immediately responds with
"result": {"code": 999, "data": "request queued"}: the request is accepted but not yet completed. Repeating the request with the sameiddoes not start the operation a second time. -
After 2–3 seconds, request the outcome with the
taskmethod and theidof the asynchronous request. You can calltaskonly synchronously:curl -sS "$API/.req/" -H 'Content-Type: application/json' -H "X-Session-Auth: $SESSION" \-d '{"jsonrpc":"2.0","id":"e5f60718-293a-4b4c-8d5e-6f708192a3b4","method":"task","params":{"id":"c41e7f20-5b6a-4d8c-9e0f-2a3b4c5d6e7f"}}' -
Repeat
taskevery few seconds whileresult.data.repliedis 0. Use a new requestideach time: a repeatedidreturns the first response. -
When
repliedbecomes 1, readresult.data.response— the response of the operation itself. Success isresponse.result; an error isresponse.errorwithcodeandmessage.
result.data also contains: method — the method of the operation; ts and reply_time — the time the operation was queued and completed, in Unix seconds; request — the original request.
The response -9704 Task not found right after queuing means that Center has not yet accepted the request for processing: repeat it in a few seconds. You get the same code for another user's operation: its author sees the outcome, and Cluster master sees the outcome of any operation. Center closes an operation that has not completed in time with the error -9706. The deadline is 6 hours; for a VM start it is 17 minutes, for a stop, suspend, or resume 32 minutes, for a restart 47 minutes, and for vm-backup-send one day.
Common errors
Any method can return these errors; the errors of the method itself are on its page. Find error.code in the table:
| Code | What happened | What to do |
|---|---|---|
-119 | Wrong name or password; error.data contains the number of failed attempts | Check the credentials |
-124 | The account is temporarily locked; the unlock time is in error.data.locked_until | Wait until that time — Set the security policy: passwords and sessions |
-123 | The account is locked indefinitely | Cluster master can unlock it |
-14777 | The request has no session | Pass it in the X-Session-Auth header |
-11000 | The session is closed or has expired | Sign in again |
-94 | The account is not allowed to sign in from this address or host name | Restrict sign-in by addresses (CIDR) and virtual hosts |
-403 | The role does not have enough permissions for the method | Assign a role |
-32602 | Invalid parameters; details are in error.message | Check the parameters against the method page |
-32601 | The method does not exist | Check the method name |
-14525 | id is not a UUID in lowercase letters | Create a new id |
| HTTP 403 | Access to the cluster API is restricted to a list of addresses, and the integration machine is not on it | Contact vStack support to add the machine address to the list. The list is set in the Center installation settings; by default, it is empty, and the API is available from any address |
More
auth-logoutcloses the current session. With"params": {"all": true}, it closes all sessions of the account, including sign-ins to the web interface.- Center does not run the same
idtwice. A synchronous repeat of the same method by the same account gets the saved response; any other repeat gets the error-1000. Center skips an asynchronous repeat without a response.