Question
How to create an API access token and how to use it for API authentication?
Answer
A secret key can be obtained from Plesk via XML API or from CLI and then used for authorization instead of the username and password. To create a secret key, specify the IP address and (or) login this secret key will be linked to. Then secret key can be specified as the KEY HTTP header of request packets.
Here is an example how to obtain secret key using CLI:
# plesk bin secret_key -c -ip-address 203.0.113.2
8774590b-3eaa-e2f8-8e28-429e7f365687
The list of existing secret keys can be obtained with the following command:
# plesk bin secret_key –list
Key: 8774590b-3eaa-e2f8-8e28-429e7f365687
Ip: 203.0.113.2
Description:
Then this key can be used with putting it into HTTP header of request packets. As an example:
# curl -kLi -H “Content-Type: text/xml” -H “KEY: 8774590b-3eaa-e2f8-8e28-429e7f365687” -H “HTTP_PRETTY_PRINT: TRUE” -d @api.rpc https://203.0.113.5:8443/enterprise/control/agent.php
Where api.rpc is a file with the XML request body.
Refer to the following documentation articles for the details:
XML API packets structure
Managing secret keys
Secret_key authentication in the XML API service