1. Home
  2. Docs
  3. WooCommerce License Keys
  4. API
  5. Handler: WordPress REST API

Handler: WordPress REST API

Using this handler will allow the License Keys API endpoints to be mounted on WordPress’ REST API, which was introduced in version 4.7.0.

Since the REST API is not running over WordPress’ admin layer, it may improve the duration of the response calls in compare to “WP Ajax”.


Configuration

Set this handler at “Dashboard” -> “WooCommerce” -> “Settings” -> “Advanced” -> “License Keys API”:

NOTE: Other settings, such as HTTP headers (CORS), will have no effect using this handler because these are handled by WordPress REST.


Route namespace

The namespace “woo-license-keys/v1” will be added to WordPress REST API.

You can verify if the License Keys API has been mounted successfully by calling the route namespace and API URL on any browse, like:

http://yourdomain.com/wp-json/woo-license-keys/v1

Replace “yourdomain.com” with your domain. Use Postman or any other application that allows testing API endpoints, to verify the response, it should return a JSON response indicating the endpoints available at the namespace, with the available request methods to use and parameters. Example:

"/woo-license-keys/v1/activate": {
            "namespace": "woo-license-keys/v1",
            "methods": [
                "POST"
            ],
            "endpoints": [
                {
                    "methods": [
                        "POST"
                    ],
                    "args": {
                        "store_code": {
                            "required": true
                        },
                        "sku": {
                            "required": true
                        },
                        "license_key": {
                            "required": true
                        },
                        "domain": {
                            "required": false,
                            "default": "localhost"
                        }
                    }
                }
            ],
            "_links": {
                "self": "http://yourdomain.com/wp-json/woo-license-keys/v1/activate"
            }
        },

Endpoints

Activate

Added as route “/woo-license-keys/v1/activate”, POST method, URL to use:

http://yourdomain.com/wp-json/woo-license-keys/v1/activate

Read more the activation endpoint documentation.

Validate

Added as route “/woo-license-keys/v1/validate”, POST method, URL to use:

http://yourdomain.com/wp-json/woo-license-keys/v1/validate

Read more the validation endpoint documentation.

Deactivate

Added as route “/woo-license-keys/v1/deactivate”, POST method, URL to use:

http://yourdomain.com/wp-json/woo-license-keys/v1/deactivate

Read more the deactivation endpoint documentation.


REST API Responses

WordPress will return their standard REST API responses whenever a required parameter is missing or invalid data types for a parameter has been provided.

These responses are specific to and when using WordPress REST API.

The following example shows a response when the store code is missing:

{
    "code": "rest_missing_callback_param",
    "message": "Missing parameter(s): store_code",
    "data": {
        "status": 400,
        "params": [
            "store_code"
        ]
    }
}

code
string
WordPress REST API error code.

message
string
Error message.

data
array
Data related to the error.

Was this article helpful to you? Yes No