Skip to content

API de WP Guardian

Introducción

Este tema va dirigido a los socios de Plesk o cPanel que quieran vender VPS con WP Guardian instalado y con licencia. Proporcionamos un procedimiento paso a paso y ejemplos de llamadas a la API necesarias para instalar y activar la licencia de WP Guardian en el VPS de un cliente.

Requisitos mínimos

Como socio de Plesk o cPanel, necesita tener acceso a sus API correspondientes: Key Administrator para Plesk y Manage2 para cPanel, respectivamente.

Having access means that you have credentials necessary to use the APIs, which are basic $AUTH_TOKEN for Key Administrator and the login/password pair for Manage2.

Nota

Si no dispone de las credenciales mencionadas, póngase en contacto con el administrador de su cuenta de Plesk o cPanel. 

El algoritmo general y los esquemas detallados

El procedimiento empieza cuando un cliente realiza un pedido (paso 1) y termina cuando usted le entrega un VPS listo para usar (paso 6). Para el resto del proceso, deberá seguir los siguientes pasos:

(2) Crear un usuario de WP Guardian.

(3) Crear una licencia de WP Guardian.

(4) Obtener el snippet de la cadena de conexión.

(5) Ejecutar el snippet de la cadena de conexión en el VPS del cliente.

Excepto el paso 3, todos los pasos anteriores son similares para Key Administrator y Manage2. Por lo tanto, ofreceremos dos secciones separadas sobre cómo crear una licencia de WP Guardian con Key Administrator y Manage2.

Para ayudarle a entender mejor las diferencias entre Key Administrator y Manage2, le adjuntamos el esquema detallado de cada una de estas API. A partir de ahí, también utilizaremos la numeración que aparece en esos esquemas (por ejemplo, Petición a la API 2.1 o Respuesta 4.2). Si se pierde en el texto, consulte los esquemas que aparecen a continuación para mayor claridad.

2. Creación de un usuario de WP Guardian

Para crear un usuario a través de la API de WP Guardian, primero debe obtener un token de administración. Para ello, póngase en contacto con un representante comercial de WP Guardian o con el equipo de atención al cliente de Plesk.

Una vez que obtenga el token de gestión, envíe la petición del siguiente patrón añadiendo el token a la cabecera Authorization:

Petición 2.1

POST https://app.wpguardian.io/api/v1/security-dashboard/management/users HTTP/1.1
Authorization: Bearer $MANAGEMENT_TOKEN
Content-Type: application/json
{
  "email": "john.doe@example.com",
  "firstName": "John",
  "lastName": "Doe"
}

Si Petición 2.1 se efectúa de forma correcta, obtendrá la respuesta del siguiente patrón:

Respuesta 2.3

HTTP/1.1 201 Created
{
  "data": {
    "userGuid": "1092a1a6-a716-400d-aba5-ad853a330561",
    "teamGuid": "1247c8bc-6d5d-41f6-9bda-007a6e6fb20c",
    "userToken": "368ded8f-883a-4759-9f28-8906c3e5136c"
  }
}

La respuesta contiene tres valores. Guarde dos de ellos (teamGuid y userToken) para usarlos más adelante:

  • teamGuid se utiliza para actualizar o terminar una licencia de WP Guardian.
  • userToken permite conectar más servidores a la cuenta del usuario.

Si Solicitud 2.1 no se efectúa correctamente, obtendrá la siguiente respuesta de error:

Respuesta de error: Invalid token response (Respuesta de token no válida)

HTTP/1.1 401 Unauthorized

Si el usuario con la información enviada ya existe, recibirá la siguiente respuesta de error:

Respuesta de error: The user already exists (El usuario ya existe)

HTTP/1.1 409 Conflict

3. Creación de una licencia de WP Guardian (Key Administrator)

Nota

Cada usuario de WP Guardian solo puede tener una licencia activa a la vez. 

Puede crear una licencia para un usuario de WP Guardian a través de la Key Administrator Partner API.

Para crear una licencia, envíe la petición del siguiente patrón:

Petición 3.1

POST https://api.central.plesk.com/30/keys?return-key-state=yes
Authorization: Basic: $AUTH_TOKEN
Content-Type: application/json
{
    "activationInfo": { "uid": "1247c8bc-6d5d-41f6-9bda-007a6e6fb20c" },
    "items": [
        {
            "item": "WPG-PLSK-1-1M"
        }
    ]
}

donde

  • $AUTH_TOKEN es un token necesario para acceder a la Key Administrator Partner API. Todos los socios de Plesk lo tienen.
  • uid en activationInfo es teamGuid de Respuesta 2.3.
  • item en items es el tipo de licencia y puede ser uno de los siguientes:

  • WPG-PLSK-1-1M

  • WPG-PLSK-5-1M
  • WPG-PLSK-10-1M
  • WPG-PLSK-30-1M
  • WPG-PLSK-50-1M

!!! nota

  Para ver la lista de todos los tipos de licencias de WP Guardian disponibles, consulte la [sección "Partner API 3.0 Constants"](https://docs.plesk.com/en-US/obsidian/partner-api-3.0/partner-api-30-constants.77835/){target=_blank} (`"category":"WP Guardian Keys"`).

If Request 3.1 is successful, you will get the response of the following pattern:

Response 3.4

HTTP/1.1 201 Created
{
  "ownerId": "700540512",
  "keyIdentifiers": {
    "keyId": 17654729,
    "keyNumber": "WPG.17654729.0000",
    "activationCode": "AB1234-CD5678-EF9012-GH123-IJ456",
    "activationLink": "https://app.wpguardian.io/licensing/activate-license?code=AB1234-CD5678-EF9012-GH123-IJ456&product=WP+Guardian+1+Site"
  },
  "parentKeyIdentifiers": null,
  "activationInfo": {
    "uid": "1247c8bc-6d5d-41f6-9bda-007a6e6fb20c",
    "activated": true
  },
  "ipAddressBinding": null,
  "nickname": "",
  "productConfigurationId": null,
  "items": [
    {
      "externalId": null,
      "item": "WPG-PLSK-1-1M"
    }
  ],
  "creationDate": "2024-09-12T10:34:11.741Z",
  "lastModificationDate": "2024-09-12T10:34:11.763Z",
  "updateDate": "2024-10-12T00:00:00.000Z",
  "expirationDate": "2024-10-22T00:00:00.000Z",
  "susExpirationDate": null,
  "susStatus": null,
  "supportExpirationDate": null,
  "supportStatus": null,
  "status": "ACTIVE",
  "terminated": false,
  "suspended": false,
  "ownerSuspended": false,
  "autoRenew": true,
  "restrictIPBinding": false,
  "frauds": [],
  "lastReportingDate": null,
  "lastReportingIp": null,
  "lastReportingOs": null,
  "childKeyIdentifiers": [],
  "overridingKeyIdentifiers": null
}

If Request 3.1 is incorrect, you will get the following error response:

Respuesta de error: Invalid token response (Respuesta de token no válida)

HTTP/1.1 401
Content-Type: application/json
Content-Length: 77
{"code":"401","type":"6011","message":"The request requires authentication."}

If the user already has an active license, you will get the following error response:

Error response: Third party error

HTTP/1.1 404 
Content-Type: application/json
{"code":"404","type":"6101","message":"Third party server returned an error"}

3. Creating a WP Guardian License (Manage2)

Unlike Key Administrator, Manage2 does not support creating a license already bound to a specific user. You first create a non-active license, generate the activation link for the license, and then send the link to the client. Once the client opens the link, the license becomes active and bound to the client.

Let's see how to go through each step.

Step 1. Create a non-active WP Guardian license by sending the API request of the following pattern:

Petición 3.1

GET https://manage2.cpanel.net/XMLlicenseAdd.cgi?output=json&packageid=P999994429&sites==500
Authorization Basic: login:password

donde

  • login:password is the login/password pair necessary to access the Manage2 API. Each cPanel partner has it.
  • packageID is the license type and can be one of the following:
  • "P999994429": "WP Guardian 500 Sites"
  • "P999994433": "WP Guardian 1000 Sites"
  • "P999994441": "WP Guardian 10000+ Sites Pay As You Go"
  • the sites parameter must match the license type. For example, if the license type is P999994429, then the sites parameter is 500, and so on.

!!! nota

  To see the list of all available WP Guardian license types, [use the Manage2 API](https://docs.cpanel.net/manage2/api/manage2-api-list-package-information/){target=_blank}.

!!! nota

  [The output of the Manage2 API](https://docs.cpanel.net/manage2/api/manage2-api-list-package-information/){target=_blank} contains two products: "WP Guardian N Sites" and "WP Guardian (cPanel Addon) N Sites Pack". You need the former.

If Request 3.1 is successful, you will get the response of the following pattern:

Response 3.2

{
    "monthly_price": "21.34",
    "status": 1,
    "yearly": 0,
    "reason": "Activated EXAMPLECOMPANY license on in the 'example' group.",
    "price": "0.00",
    "promoinfo": "",
    "licenseid": "17654729"
}

From the response, you need to copy the licenseid value to use it later.

Step 2. Generate the activation link by sending the API request of the following pattern:

Request 3.3

{
GET https://manage2.cpanel.net/XMLlicenseInfo.cgi?output=json&liscid=17654729
Authorization Basic: login:password
}

where liscid is licenseid from Response 3.2.

If Request 3.3 is successful, you will get the response of the following pattern:

Response 3.4

{
    "licenses": {
        "17654729": {
            "accounts": 1,
...
            "activation_link": "https://app.wpguardian.io/licensing/activate-license?code=A00300-GEX111-577J59-A6AG72-AEKX66&product=WP+Guardian+500+Sites ",
...
        }
    },
    "reason": "OK",
    "status": 1,
    "version": 0.7
}

Step 3. Save the activation link received in Response 3.4, and then send it to the client. Make sure that the client opens the link. Opening the link activates the license and binds it to the client.

4. Getting the Connection String Snippet

The connection string snippet is a script you need to get from the WP Guardian API. By running the snippet on a client's server, you connect it to WP Guardian.

To get the snippet, send the API request of the following pattern:

Request 4.1

GET https://app.wpguardian.io/api/v1/security-dashboard/connection-snippet
Authorization: Bearer $USER_TOKEN
Content-Type: application/json

where $USER_TOKEN is userToken from Response 2.3.

If the API request was correct, you will get the response of the following pattern:

Response 4.2

{
    "data": {
        "expireAt": "2024-09-24T17:18:51.697Z",
        "snippet": "<script to run on a client's VPS>"
    }
}

5. Running the Snippet on a Client's VPS

The last step is to run the connection string snippet received during the previous step on the client's VPS. Once you have done so, the VPS with WP Guardian is all ready. Congratulations!

Nota

The snippet automatically connects a client's VPS to WP Guardian.
If, for any reason, the snippet fails, you can resolve the issue by [connecting a VPS to WP Guardian manually]( https://docs.wpguardian.io/index.html#connecting-servers-to-wp-guardian){target=_blank}.
Back to top