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
  • Receiving A Response

Receiving A Response

Our API sends responses in JSON headers. You can easily use these response in your app to activate/deactivate functions.

Here’s an example scenario:

  1. Your app integrates a form to collect license keys.
  2. Your customer pastes in their key and hits the submit button.
  3. The form sends a request to our API, which responds with the following based on the results:
    • If the key is valid the response will look like: {“valid” : “1”}
    • If the key is invalid the response will look like: {“valid” : “0”}
    • If the process produces an error the response will look like: {“ERROR”:”Error message will be here”}

See the documentation on our JSON responses, including examples. We also have documentation on error messages.

Using JSON Responses In Your Code #

After the API returns a message, you could craft your code to do the following:

  • Look for “valid” and see if it set to “1”
    • If found, save a variable $activated to “true” to a local file or database. This represents the confirmation the key was activated.
    • If not found or “valid” is “0”, display the returned error message or a custom message

Here is an example in PHP of how to look for “valid” in the response data and what to do if it is “1” or “0”. You can find more information in our documentation on JSON responses.

... 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,
];
  • Next, add a simple if statement to the critical functions of your app to check the status inside the local file.
    • If $activated is “true”, then run normally
    • If not, show an error message such as “Please activate your license”, or it could redirect to the license key form

Here is an example in PHP of how to lock your app down until the key is successfully validated.

// Function to check activation status
function checkActivationStatus() {
    $activationFile = 'activation_status.txt';
    if (file_exists($activationFile)) {
        $contents = file_get_contents($activationFile);
        if (strpos($contents, 'activated = true') !== false) {
            return true;
        }
    }
    return false;
}

// Example usage in a critical function
function criticalFunction() {
    if (checkActivationStatus()) {
        // Run the function normally
        echo "Function is running normally.";

       ... rest of code

    } else {
        // Show an error message or redirect to the license key form
        echo "Please activate your license.";
        exit; // Stop further execution if license is not activated
    }
}

// Call the critical function
criticalFunction();

Making It Even Better #

From there you also have the possibility to check the key every time the app starts or once a day in the case of web apps. We recommend adding this check to make refunds easier. See our documentation on refund best practices.

You can also provide offline key support by checking if the user has an internet connection when the app starts and, if true, check the key using our API. If there is no internet it can skip the live API check and use the previously saved results stored locally in a file or database. This is the best of both worlds.

Handling Errors #

Error messages are also sent via the JSON header and can be displayed to the end user. However if you wish to show custom messages you can.

See our full documentation on handling error messages.

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

How can we help?

Updated on April 15, 2024
Making API CallsExample JSON Response

Powered by BetterDocs

Table of Contents
  • Using JSON Responses In Your Code
  • Making It Even Better
  • Handling Errors
  • 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