Skip to content
Sign Up For Free
BatchKeys License Key SaaS
  • Pricing
  • Try Demo
  • Docs
  • SupportExpand
    • Tickets
  • AboutExpand
    • Contact
  • Dashboard
BatchKeys License Key SaaS

Getting Started

11
  • Setting Up An Account
  • Your Dashboard
  • Generating Keys
  • Viewing And Editing Keys
  • Viewing/Editing An Individual Key’s Details
  • Bulk Deleting Keys
  • Importing Keys
  • Encoding And Decoding PHP
  • Handling Refunds
  • Unbanning A Valid End User
  • Requesting An Enterprise or Custom Plan

Integrations

14
  • Inserting Code Into Your App
  • Making API Calls
  • Receiving A Response
  • Example JSON Response
  • Assigning Keys To A Domain Name
  • Generating Unique UUIDs
  • Assigning Keys To A UUID
  • Checking Keys Daily Using A Cron Job
  • Checking Keys At Startup
  • Consuming And Topping Up Tokens For Token-Based Keys
  • Server-Side Proxy For Client-Side JavaScript Connections
  • Forms To Collect A Key
  • Adding BatchKeys To A WordPress Plugin
  • Adding BatchKeys To A WordPress Theme

Best Practices

13
  • Using Domain/UUID Settings To Upsell Your App
  • Staying Within Rate Limits
  • Handling Errors
  • Dealing With Connection Failures And Rechecks
  • Securing Keys
  • Working Around Hardware Changes With V5 UUIDs
  • Working Around V4 UUID Security Concerns
  • Creating Good Validation Forms
  • How We Use UUIDs To Secure Keys
  • A Note About Example Codes
  • Can We Create Custom Code For You?
  • Maximum Key Limits Per Plan
  • Using A License Key Service In A Mobile App
  • Home
  • Docs
  • Integrations
  • Example JSON Response

Example JSON Response

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.

Was this Helpful?
Still stuck? How can we help?

How can we help?

Updated on April 15, 2024
Receiving A ResponseAssigning Keys To A Domain Name

Powered by BetterDocs

Table of Contents
  • Using JSON Messages
    • Valid: 0
    • Valid: 1
  • Handling Messages
  • Error Messages
  • Get Early Access
  • Try Demo
  • Status
  • API Tester
  • Docs
  • Support
  • Feature Request
  • Feedback
  • About
  • Contact
  • Sitemap
  • Coupons

TOS

Privacy Policy

SLA

© 2025 Batch Keys | Created and maintained by Kayce Media Group

  • Pricing
  • Try Demo
  • Docs
  • Support
    • Tickets
  • About
    • Contact
  • Dashboard