Applicable to:
- Plesk Obsidian for Linux
- Plesk Obsidian for Windows
- Plesk for Linux
- Plesk for Windows
Question
Is it possible 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 CLI utilities using CLI gate. The full list of supported utilities can be found using following 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:
-
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\", \"jdoe@example.com\",\"-mailbox\", \"true\", \"-passwd\", \"1qazXSW@\" ]}"
{
"code": 0,
"stdout": "SUCCESS: Creation of mailname 'jdoe@example.com' complete",
"stderr": ""
-
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.php
method:# 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\", \"jdoe@example.com\" ]}"
Comments
0 comments
Please sign in to leave a comment.