Question
Is it possible to manage Plesk via REST API?
How to manage Plesk via REST API?
Answer
Starting from Plesk Onyx 17.8, it is possible to use REST API for managing Plesk.
Besides this, REST API has the ability to call Plesk CLI utilities. The full list of supported CLI utilities can be found using following API request:
# curl -k -u admin:password -X GET "https://plesk.example.com:8443/api/v2/cli/commands/"
Find several examples of using REST API in the examples below:
Using REST API methods
-
To list all domains:
# curl -k -X GET -u admin:password -H "Content-Type: application/json" -H "Accept: application/json" "https://203.0.113.2:8443/api/v2/domains"
[
{
"id": 1,
"created": "2018-12-17",
"name": "example.com,
"ascii_name": "example.com",
"guid": "4e0da092-de42-4048-9459-989b5cb942f2",
"hosting_type": "virtual"
},
{
"id": 2,
"created": "2018-12-17",
"name": "example.org",
"ascii_name": "example.org",
"guid": "f1b6e826-c884-4fa2-832b-5813c09002d3",
"hosting_type": "virtual"
},
{
"id": 3,
"created": "2018-12-17",
"name": "example.net",
"ascii_name": "example.net",
"guid": "03f62600-db70-4a94-9818-ab12a57a1425",
"hosting_type": "virtual"
} -
To create a mailbox:
# curl -k -X POST -u admin:password "https://203.0.113.2:8443/api/v2/cli/mail/call" -H "accept: application/json" -H "Content-Type: application/json" -d "{ "params": [ "--create", "[email protected]","-mailbox", "true", "-passwd", "1qazXSW@" ]}"
{
"code": 0,
"stdout": "SUCCESS: Creation of mailname '[email protected]' complete",
"stderr": ""
Using REST API to call CLI utilities
-
Show the information about the subscription:
# curl -k -X POST -u admin:password "https://203.0.113.2:8443/api/v2/cli/subscription/call" -H "accept: application/json" -H "Content-Type: application/json" -d "{ "params": ["--info", "example.com"]}"
-
Show help for
mail
utility:# curl -k -X POST -u admin:password "https://203.0.113.2:8443/api/v2/cli/mail/call" -H "accept: application/json" -H "Content-Type: application/json" -d "{ "params": [ "--help" ]}"
-
Use CLI gate to check SpamAssassin status for the mailbox:
# curl -k -X POST -u admin:password "https://203.0.113.2:8443/api/v2/cli/spamassassin/call" -H "accept: application/json" -H "Content-Type: application/json" -d "{ "params": [ "--info", "[email protected]" ]}"
-
Use CLI gate to add additional user using secret key instead of admin password
# curl -k -X 'GET' -H 'X-Api-Key: ******************' 'https://203.0.133.2:8443/api/v2/cli/user/call' -H "accept: application/json" -H "Content-Type: application/json" -d @user.json
The content of the user.json file:
{ "params": [ "--create", "adduser", "-owner", "admin", "-passwd", "samplepassword", "-cname", "User", "-role", "webmaster" ] }