How to lookup a barcode value and return product data in PHP

Cloudmersive
1 min readAug 6, 2019

--

This task is a lot simpler than you might think, thanks to our barcode API. Start by installing the client using Composer:

composer require cloudmersive/cloudmersive_barcode_api_client

Then we’ll use barcodeLookupEanLookup:

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');
$apiInstance = new Swagger\Client\Api\BarcodeLookupApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$value = "value_example"; // string | Barcode value
try {
$result = $apiInstance->barcodeLookupEanLookup($value);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling BarcodeLookupApi->barcodeLookupEanLookup: ', $e->getMessage(), PHP_EOL;
}
?>

All done! How easy was that? If you need to generate barcodes or QR codes we have other functions that support that, as well as being able to scan images for barcodes and turn the results.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet