You should always expect some sort of JSON response back from every key check. Validation responses as well as error messages are sent back via JSON headers unless a critical error or connection error has occurred.
The JSON messages will look something like:
{"valid" : "0"}
This particular message indicates the key did not validate. See more about receiving a response and making calls to the API.
Using JSON Messages #
The main purpose of JSON response messages is to check for the existence of “valid” and then see if it is 0 or 1. You can use that information to unlock your app’s critical features. It’s also a good idea to save this validation to a local file or database for offline fallback.
Valid: 0 #
If Valid is 0 it means the key failed to validate. This can be because the key was not found, the API auth key provided was not found, the key is being used on an unauthorized domain (for domain locked keys), or the UUID of the current end user does not match the UUID already assigned to the key (for UUID locked keys).
Valid: 1 #
If Valid is 1 then the key is valid. It is a legitimate key assigned to a developer and the request came from the correct domain/UUID.
{"valid" : "1"}
Handling Messages #
The example PHP code below assigns the decoded JSON response to a variable and then searches that variable for the word “valid” and also checks if “valid” is set to 1. It then sets a boolean $activated to true and saves this information in a local file.
... rest of code
// Assume $licenseKey is defined earlier in the code
// Initialize variables
$activated = false;
$message = '';
// Process the response
$responseData = json_decode($response, true);
// Check if the API call was successful based on the valid field
if (isset($responseData['valid']) && $responseData['valid'] == "1") {
// Set activated to true and prepare a success message
$activated = true;
$message = 'Activation successful.';
// Save $licenseKey and activated = true to a local file
$fileContent = "Key = $licenseKey\nactivated = true";
file_put_contents('activation_status.txt', $fileContent);
} else {
// Set activated to false and prepare a failure message
$activated = false;
$message = 'Activation failed.';
}
// Return the results
return [
'activated' => $activated,
'message' => $message,
];
Ideas for a successful validation are: showing a success message, saving the validation locally to a variable or file, or redirecting to your apps main page/screen. The goal is to use that information to unlock the functions in your app that require a license key.
Error Messages #
Many error messages are sent via JSON in case you want to process them. You can handle these messages in many different way, including ignoring them entirely. You could show a generic message, show a detailed message, or make your own custom error messages for each one.
Here is an example JSON error message.
{"ERROR":"This is an error message"}
For a list of error messages or to learn more on error handling, see our documentation on handling errors.