Skip to content

Latest commit

 

History

History

php

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Short Code Generator API - PHP Package

Short Code Generator creates custom alphanumeric short codes for vouchers, referral tokens, and redirect slugs. Specify a length, batch count, and character set like numeric, hex, or Base58 to receive an array of random strings.

Installation

Install via Composer:

composer require apiverve/shortcodegenerator

Getting Started

Get your API key at APIVerve

Basic Usage

<?php

require_once 'vendor/autoload.php';

use APIVerve\Shortcodegenerator\Client;

// Initialize the client
$client = new Client('YOUR_API_KEY');

// Make a request
$response = $client->execute([
    'count' => 1,
    'length' => 8,
    'charset' => 'alphanumeric'
]);

// Print the response
print_r($response);

Error Handling

use APIVerve\Shortcodegenerator\Client;
use APIVerve\Shortcodegenerator\Exceptions\APIException;
use APIVerve\Shortcodegenerator\Exceptions\ValidationException;

try {
    $response = $client->execute(['count' => 1, 'length' => 8, 'charset' => 'alphanumeric']);
    print_r($response['data']);
} catch (ValidationException $e) {
    echo "Validation error: " . implode(', ', $e->getErrors());
} catch (APIException $e) {
    echo "API error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
}

Debug Mode

// Enable debug logging
$client = new Client(
    apiKey: 'YOUR_API_KEY',
    debug: true
);

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "codes": [
      "bgiFznFh",
      "jr84hHsG",
      "Q77qABwn",
      "gvMjXxXs",
      "WDPJzCsi"
    ],
    "count": 5,
    "length": 8,
    "charset": "alphanumeric",
    "url_safe": true
  }
}

Requirements

  • PHP 7.4 or higher
  • Guzzle HTTP client

Documentation

For more information, visit the API Documentation.

Support

License

This package is available under the MIT License.