Skip to main content
Version: V2

Barcodes API Wrapper for PHP

Elevate your PHP-based applications by effortlessly integrating with the Barcodes.GG API. Our custom PHP SDK ensures you get the best of both worlds - efficiency and ease of use. Dive in and explore the barcode realm with PHP.

Prerequisites​

Your PHP environment should have the cURL extension enabled. Most servers come with this extension by default, but it's always good to double-check.

SDK Wrapper Code​

class BarcodesAPI {
private $apiKey;
private $baseUrl = 'https://barcodes.gg/api';

public function __construct($apiKey) {
$this->apiKey = $apiKey;
}

private function makeRequest($endpoint) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseUrl . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $this->apiKey
));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return json_decode($result, true);
}

public function searchProducts($query) {
return $this->makeRequest("/product/search?query=$query");
}

public function lookupBarcode($ean, $showData = 1, $fields = '*') {
return $this->makeRequest("/barcode/lookup/$ean?show_data=$showData&fields=$fields");
}

public function getImage($styleCode) {
return $this->makeRequest("/image/$styleCode");
}

public function reverseLookupBySKU($sku, $isVerified = 1, $page = 1) {
return $this->makeRequest("/barcode/lookup/sku/$sku?is_verified=$isVerified&page=$page");
}
}

Integration Steps​

  1. Initialization: Get the ball rolling by setting up the BarcodesAPI class.
$api = new BarcodesAPI('YOUR_API_KEY');

Remember to replace 'YOUR_API_KEY' with your genuine API key for unhindered access.

  1. Product Search: Embark on a seamless product search expedition.
print_r($api->searchProducts('dd1503-100'));
  1. Barcode Lookup: Dive deeper into the product's essence using its unique barcode.
print_r($api->lookupBarcode('195245980597'));
  1. Image Retrieval: Fetch captivating product images using just the style code.
print_r($api->getImage('DH4756-100'));
  1. SKU-based Reverse Barcode Lookup: Turn things around by using the SKU to retrieve barcodes.
print_r($api->reverseLookupBySKU('DD1391-100'));

Each method yields an associative array, granting you the flexibility to mold the data as per your application's needs.

Dive into a transformative barcode integration experience with PHP.