Code Example

$curl = curl_init();

$endpoint = '{{domain}}/wp-json/wclm/v3/create-license-key';
$parameters = array(
        // Required, JSON Array of license keys
        'license_keys' => '["FFFF-FFFF-FFFF-FFFF", "FFFF-FFFF-FFFF-1234"]',

        // Required, WooCommerce Product ID
        'product_id' => '236',

        // Optional, WooCommerce Variation  ID, Default 0. 0 = Product has no variations.
        'variation_id' => '0',

        // Optional, License owner first name
        'owner_first_name' => 'Test',

        // Optional, License owner last name
        'owner_last_name' => 'Test',

        // Optional, License owner email
        'owner_email_address' => 'contact@domain.ltd',

        // Optional, Default 1
        'delivery_limit' => '1',

        // Optional, Default 1
        'remaining_delivery_times' => '1',

        // Optional, Default 1
        'activation_limit' => '3',

        // Optional, Default 1
        'remaining_activations' => '3',

        // Optional, Format YYYY-MM-DD, Default null
        'activation_date' => '2021-04-12',

        // Optional, Format YYYY-MM-DD, Default null
        'expiration_date' => '2022-04-12',

        // Optional, Format YYYY-MM-DD, Default null
        'sold_date' => '2021-04-12',

        // Optional, Default 0
        'validity_days' => '365',

        // Optional, Default 0
        'order_id' => '23',

        // Optional, Default available
        'license_status' => 'sold'
    );

curl_setopt_array($curl, array(
     CURLOPT_URL => $endpoint,
     CURLOPT_RETURNTRANSFER => true,
     CURLOPT_MAXREDIRS => 10,
     CURLOPT_TIMEOUT => 0,
     CURLOPT_FOLLOWLOCATION => true,
     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
     CURLOPT_CUSTOMREQUEST => 'POST',
     CURLOPT_POSTFIELDS => $parameters,
     CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
     CURLOPT_SSL_VERIFYPEER => false,
     CURLOPT_HTTPHEADER => array(
         // Authenticated user token
         'Authorization: Bearer {{User Token}}'
     )
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

API Responses

{
    "response": {
        "result": "error",
        "code": "960",
        "message": "Invalid product ID",
        "api_timestamp": 'current timestamp'
    },
    "signature": "Signature or OpenSSL error"
}
{
    "response": {
        "result": "error",
        "code": "961",
        "message": "Invalid variation ID",
        "api_timestamp": 'current timestamp'
    },
    "signature": "Signature or OpenSSL error"
}
{
    "response": {
        "result": "error",
        "code": "980",
        "message": "Invalid order ID",
        "api_timestamp": 'current timestamp'
    },
    "signature": "Signature or OpenSSL error"
}
{
    "response": {
        "result": "error",
        "code": "981",
        "message": "The order doesn't have an item with the given product ID",
        "api_timestamp": 'current timestamp'
    },
    "signature": "Signature or OpenSSL error"
}
{
    "response": {
        "result": "error",
        "code": "982",
        "message": "The order doesn't have an item with the given variation ID",
        "api_timestamp": 'current timestamp'
    },
    "signature": "Signature or OpenSSL error"
}
{
    "response": {
        "result": "success",
        "code": "962",
        "message": "License key(s) created",
        "data": {
            "total": 2,
            "added": 2,
            "duplicate": 0,
            "duplicates_allowed": false
        },
        "api_timestamp": 'current timestamp'
    },
    "signature": "Signature or OpenSSL error"
}

WordPress’s built-in REST API responses.

{
    "code": "rest_forbidden",
    "message": "Sorry, you are not allowed to do that.",
    "data": {
        "status": 403
    }
}
Was this article helpful to you? Yes No