Question
How to manage WordPress instances (installation, theme management) over API?
Answer
For that, REST API can be used. To get the list of all possible operations with WP Toolkit, run this command on a Plesk server:
# plesk bin extension --call wp-toolkit
Examples
- Create a secret key:
# curl -iku admin:password -X POST -H 'Content-Type: application/json' -d'{}' https://plesk.example.com:8443/api/v2/auth/keys
{
"key": "c39cc4dd-b291-b64b-9b09-aad0bec0ffee"
}
- Use the secret key and CLI endpoint to manage instances:
- Install WordPress on example.net:
# curl -ikX POST -H 'Content-Type: application/json' -H "X-API-Key: c39cc4dd-b291-b64b-909-aad0bec0ffee" -d'{ "params": ["--call", "wp-toolkit", "--install", "-domain-name", "example.net"] }' https://127.0.0.1:8443/api/v2/cli/extension/call
- Install a theme on instance, e.g. instance 8:
# curl -ikX POST -H 'Content-Type: application/json' -H "X-API-Key: c39cc4dd-b291-b64b-9b09-aad0bec0ffee" -d'{ "params": ["--call", "wp-toolkit", "--wp-cli", "-instance-id", "8", "--", "theme", "install", "https://downloads.wordpress.org/theme/corporatecorner.1.0.6.zip"] }' https://127.0.0.1:8443/api/v2/cli/extension/call
- Activate a theme on instance, e.g. instance 8:
# curl -ikX POST -H 'Content-Type: application/json' -H "X-API-Key: c39cc4dd-b291-b64b-9b09-aad0bec0ffee" -d'{ "params": ["--call", "wp-toolkit", "--wp-cli", "-instance-id", "8", "--", "theme", "activate", "corporatecorner"] }' https://127.0.0.1:8443/api/v2/cli/extension/call
- To pass the variable to the REST API call use the
env
option as in the example below (e.g. install wordpress on test.com with credentials [email protected]/new_password):# curl -ikX POST -H 'Content-Type: application/json' -H "X-API-Key: c39cc4dd-b291-b64b-9b09-aad0bec0ffee" -d'{ "params": ["--call", "wp-toolkit", "--install", "-domain-name", "test.com", "-admin-email", "[email protected]"], "env": { "ADMIN_PASSWORD": "new_password" } }' https://127.0.0.1:8443/api/v2/cli/extension/call