Hoster API Documentation

  1. Overview
  2. Hoster API
  3. Hoster API Documentation

Hoster API Plugin Documentation

Overview

The Hoster API plugin provides REST endpoints for managing licenses. It supports:

  • Create License: Create a new license and assign it to a user.

  • Update License: Update a license using flat parameters (the endpoint assembles the update data internally).

  • Retrieve License Details: Retrieve full details for a license (such as license number, expiry, activations, and status).

Each endpoint uses Bearer token authentication. The plugin accepts flat JSON parameters for both creating and updating licenses. Dates can be sent in many standard formats (including UK format DD/MM/YYYY) and will be converted to the standard YYYY‑MM‑DD format.

All plugin functions are prefixed with rup_hoster_api_.

Endpoints

1. Create License Endpoint

Required Parameters:

  • download_id (integer):
    The ID of the related download post.

  • status (string):
    The license status (e.g., "active" or "expired").

  • User Identification (Choose one):

    • user_id (integer):
      The WordPress user ID to assign the license.

    • email (string):
      The email address of the user.

      • If a user with this email exists, that user’s ID is used.

      • If not, a new user is created using the email as the username.

      • Optional (for new user creation):

        • first_name (string): The user’s first name.

        • last_name (string): The user’s last name.

        • role (string): The user’s role. If omitted, the default new user role (set in admin settings) is used.

Optional License Parameters:

  • enable_activation_limit (boolean):
    Set to true to enforce an activation limit; set to false for unlimited activations.
    Note: Although some automators send these as strings (e.g., "false"), the API converts them properly.

  • activation_limit (integer):
    Maximum number of activations allowed. For unlimited activations, set to 0.

  • expiry_date (string):
    The expiry date for the license. This date can be provided in various formats—including UK format (DD/MM/YYYY) or ISO (YYYY-MM-DD)–and will be converted to YYYY‑MM‑DD. An empty expiry date indicates a lifetime license.

2. Update License Endpoint

This endpoint now accepts flat parameters (instead of a nested update_data object) and assembles the update data internally.

Required Parameter:

  • license_id (integer):
    The WordPress post ID of the license to update.

Optional Parameters (Flat):

  • status (string):
    New license status (e.g., "expired").

  • expiry_date (string):
    New expiry date for the license. This can be in any common format (e.g., "13/05/2026" for UK format or "2026-05-13" for ISO). It will be converted to YYYY‑MM‑DD format.
    An empty expiry_date indicates a lifetime license.

  • activation_limit (integer):
    New maximum activation limit.

The endpoint builds an associative array with the provided fields, converts the date formats as needed, and passes it to your license update filter.

Examples

Example 1: Create License with Email and UK Date Format

Request JSON:

jsonCopy{
"download_id": 10,
"email": "hello@wpcode.dev",
"status": "active",
"enable_activation_limit": "false",
"activation_limit": "0",
"expiry_date": "13/02/2025"
}

Notes:

The API checks if a user exists for hello@wpcode.dev; if not, it creates a new user using that email as the username.

The expiry date in UK format is converted to "2025-02-13".

Example 2: Create License with Existing User ID and ISO Date Format

Request JSON:

jsonCopy{
"download_id": 10,
"user_id": "1",
"status": "active",
"enable_activation_limit": "false",
"activation_limit": "0",
"expiry_date": "2025-02-13"
}

Note:

The provided user_id is used directly (bypassing email lookup/creation).

Example 3: Update License with Flat Parameters

Request JSON:

jsonCopy{
"license_id": 123,
"status": "expired",
"expiry_date": "13/05/2026",
"activation_limit": 10
}

Notes:

The expiry date "13/05/2026" (UK format) is converted to "2026-05-13".

Only the provided fields are updated for the license with ID 123.

Additional Notes

  • Authentication:
    Every API request must include a valid Bearer token in the HTTP header:

    Authorization: Bearer <your_api_token>
    
  • Default New User Role:
    Administrators can set a default role for new users via the plugin’s admin settings page. When creating a new user via email, if no "role" parameter is provided, the default role is used.

  • Type Conversion:
    The API converts values sent as strings into the correct data types. For example, "false" is properly interpreted as a boolean false, and numeric fields are cast to integers.

  • Date Conversion:
    The helper function checks if the date is in UK format (DD/MM/YYYY) using a regular expression. If it matches, it uses DateTime::createFromFormat('d/m/Y', $date_raw) to convert it to YYYY‑MM‑DD. Otherwise, it falls back to strtotime() for common formats.

  • Meta Keys & Post Types:
    The retrieve-license-details endpoint assumes that license information is stored


Was this article helpful?