Getting started with WEKA REST API
The WEKA system provides a RESTful API that allows you to automate operations and integrate them into your workflows or monitoring systems. A solid understanding of the relevant WEKA CLI commands and parameters is important when working with the REST API. For example, when creating a filesystem using the POST /fileSystems service, refer to the corresponding CLI documentation for guidance.
Access the REST API
You can access the REST API using one of the following methods:
Direct access: Use port 14000 and the URL
/api/v2.Through the cluster: Browse to
https://<cluster name or IP>:14000/api/v2/docs.Through the WEKA GUI: Select the three dots on the upper right menu and select REST API.

WEKA static API: Browse to api.docs.weka.io and select the required REST API version from the definition selector. You can also generate client code by using the OpenAPI client generator with the corresponding .json definition file.

Explore the REST API through the GUI

Obtain an access token
To use the WEKA REST API, provide an access or refresh token.
You can generate an access or refresh for the REST API usage through the CLI or the GUI. See Obtain authentication tokens.
You can also call the login API to obtain access or refresh tokens through the API, providing it with a username and password.
If you already obtained a refresh token, you can use the login/refresh API to refresh the access token.
import requests
url = "https://weka01:14000/api/v2/login"
payload="{\n \"username\": \"admin\",\n \"password\": \"admin\"\n}"
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
import requests
url = "https://weka01:14000/api/v2/login/refresh"
payload="{\n \"refresh_token\": \"REPLACE-WITH-REFRESH-TOKEN\"\n}"
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
The response includes the access token (valid for 5 minutes) to use in the other APIs requiring token authentication, along with the refresh token (valid for 1 year), for getting additional access tokens without using the username/password.
{
"data": [
{
"access_token": "ACCESS-TOKEN",
"token_type": "Bearer",
"expires_in": 300,
"refresh_token": "REFRESH-TOKEN"
}
]
}Call the REST API
Once you obtain an access token, you can call WEKA REST API commands with it. For example, you can query the cluster status:
import requests
url = "https://weka01:14000/api/v2/cluster"
payload={}
headers = {
'Authorization': 'Bearer REPLACE-WITH-ACCESS-TOKEN'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Related topics
Last updated