Articles in this section

How to manage WordPress instances (WordPress installation, theme management) over API

Plesk for Windows kb: how-to Plesk for Linux ext: wptk ABT: Group A

Applicable to:

  • Plesk for Linux
  • Plesk for Windows

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

  1. 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"
    }

  1. 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 mail@test.com/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", "mail@test.com"], "env": { "ADMIN_PASSWORD": "new_password" } }' https://127.0.0.1:8443/api/v2/cli/extension/call

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.