API Overview
Our powerful API enables you to automate the management of your cloud services.
Accessing the API requires an API ID and key, which can be created from the API tab.
An API call consists of:
- A category and action, like "vm/create" (where 'vm' is the category and 'create' is the action)
- A set of parameters, which will be encoded and transmitted in the POST body
- An HTTPS request is made and the server will send back a JSON response
Libraries
We provide open source PHP and Python libraries for our API. These libraries provide a function that takes a category, action, and parameters, and returns the server response object.
Here is a list of available libraries:
- PHP: lndynamic-api
- Python: lndynamic-api
- Golang: our Lobster project includes a component exposing a Golang client API
- C#: (third-party) rickparrish/lndapi
- Ruby: (third-party) nomoon/lunanode
- PHP: (third-party, installable from composer) sdavis1902/lunanode-api-php
Technical Details
Given an API ID, API key, category, action, and parameters, the steps to perform the request are described below. You can also refer to our libraries for examples in PHP and Python.
- Create the string-to-string request map by taking the parameters, and adding in two additional keys {"api_id": API ID} and {"api_partialkey": first 64 characters of API key}.
- JSON-encode the request array to get a raw request message.
- The nonce is the current UTC time in seconds since epoch (in PHP,
$nonce = time();
). - The handler path is "{category}/{action}/", e.g. "vm/create/" for creating a VM.
- Then, the target URL is https://dynamic.lunanode.com/api/{handler path}, e.g. https://dynamic.lunanode.com/api/vm/create/.
- Calculate the signature as SHA512-HMAC({handler_path}|{raw request message}|{nonce}), using the 128-character API key as the HMAC key. Here, we are signing the string formed from concatenating the handler path, raw request message, and nonce delimited by pipe (|) characters.
- Submit POST request to target URL with these form keys (they should be form-URL-encoded):
- req - the raw request message
- signature - hex-encoding of SHA512-HMAC output
- nonce - the nonce value, as a string
- The server will respond with a JSON entity.
Response Objects
The response is a JSON object, and will always include the success
attribute.
If the request is successful, success
will be 'yes', otherwise it will be 'no'.
On unsuccessful requests, an error
attribute will also be present, providing details on the error that happened.
Here is an example response where we fail to provide a required parameter:
{ "success":"no", "error":"required parameter hostname not set" }
Documentation
The tabs on the left detail the various components of the API. If you're just getting started, the API Quickstart may also be helpful.