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
  • Best Practices
  • Dealing With Connection Failures And Rechecks

Dealing With Connection Failures And Rechecks

Before sending a key check it’s good practice to check for an internet connection first via a ping. This will solve most of your connection errors.

If a license key check fails due to a connection error it’s reasonable to send the check again. This could be done right away or a short time after, but do not send continuous checks until a success message is received. These will almost always fail in quick succession if the original check failed, and then your end user will be timed out by our AI security systems and unable to receive any more license key checks for a time.

Making A Connection #

The proper way to build a license key check is to:

  • Ping a large domain such as google.com or a dedicated pinging service
    • If the ping fails, assume the end user doesn’t have an internet connection
    • If successful, send the key check to our API
      • Then, if the key check fails during the check due to a connection error, ping https://batchkeys.com
        • If successful, try the key again up to three times
        • If the ping failed, wait some times and try pinging https://batchkeys.com again

Here is a sample code in Python utilizing these practices.

import os
from dotenv import load_dotenv
import requests
import subprocess
import time

# Load environment variables from .env file
load_dotenv()

def ping(domain):
    # Using the 'ping' command to check connectivity
    try:
        output = subprocess.check_output(['ping', '-c', '1', domain], stderr=subprocess.STDOUT, universal_newlines=True)
        return True
    except subprocess.CalledProcessError:
        return False

def check_key(key, uuid):
    auth_key = os.getenv('AUTH_KEY')
    api_url = os.getenv('API_URL')
    headers = {
        'auth': auth_key,
        'key': key,
        'uuid': uuid
    }
    try:
        response = requests.get(api_url, headers=headers)
        if response.status_code == 200:
            return True
    except requests.exceptions.RequestException:
        return False
    return False

def main():
    key = 'your_key_here'
    uuid = 'your_uuid_here'
    if ping('google.com'):
        if check_key(key, uuid):
            print('Key check successful.')
        else:
            print('Key check failed. Retrying...')
            for attempt in range(3):
                if ping('batchkeys.com'):
                    if check_key(key, uuid):
                        print('Key check successful on retry.')
                        break
                    else:
                        print(f'Attempt {attempt + 1} failed. Retrying...')
                else:
                    print('Waiting and retrying ping to batchkeys.com...')
                    time.sleep(300)  # Wait for 5 minutes before retrying
                    continue
            else:
                print('Key check failed after multiple attempts.')
    else:
        print('No internet connection.')

if __name__ == '__main__':
    main()

Pinging too quickly or sending too many API requests in a short amount of time will rate limit your users so be mindful of how fast you send these pings/requests. See our documentation on staying within rate limits for more info.

Other Error Messages #

Our API sends detailed error messages back to your app in the form of JSON headers. If you received one of these messages you did not experience a connection error from BatchKeys. For a detailed list of error messages, please see our documentation on handling errors.

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

How can we help?

Updated on April 4, 2024
Handling ErrorsSecuring Keys

Powered by BetterDocs

Table of Contents
  • Making A Connection
  • Other 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