Skip to main content

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/.
  • curl and jq are 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. uuidgen generates it; on macOS, use uuidgen | 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​

  1. Send the auth method with the account name and password:

    API=https://203.0.113.10/.api/V4
    AUTH=$(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'
  2. Make sure that result.code is 1 and result.data.message is authenticated. Code 2 and must change password mean 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.

  3. Save the session as APIEndpoint00= followed by the value of result.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​

  1. Pass the session in the X-Session-Auth header 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 Cookie header: the response is -14777 Not authenticated.

  2. Read the response: result.code is 1, and result.data contains 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​

  1. 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 same id does not start the operation a second time.

  2. After 2–3 seconds, request the outcome with the task method and the id of the asynchronous request. You can call task only 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"}}'
  3. Repeat task every few seconds while result.data.replied is 0. Use a new request id each time: a repeated id returns the first response.

  4. When replied becomes 1, read result.data.response — the response of the operation itself. Success is response.result; an error is response.error with code and message.

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:

CodeWhat happenedWhat to do
-119Wrong name or password; error.data contains the number of failed attemptsCheck the credentials
-124The account is temporarily locked; the unlock time is in error.data.locked_untilWait until that time — Set the security policy: passwords and sessions
-123The account is locked indefinitelyCluster master can unlock it
-14777The request has no sessionPass it in the X-Session-Auth header
-11000The session is closed or has expiredSign in again
-94The account is not allowed to sign in from this address or host nameRestrict sign-in by addresses (CIDR) and virtual hosts
-403The role does not have enough permissions for the methodAssign a role
-32602Invalid parameters; details are in error.messageCheck the parameters against the method page
-32601The method does not existCheck the method name
-14525id is not a UUID in lowercase lettersCreate a new id
HTTP 403Access to the cluster API is restricted to a list of addresses, and the integration machine is not on itContact 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-logout closes 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 id twice. 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.