How to lookup a Barcode Value and return Product Data in PHP

Cloudmersive
2 min readMar 30, 2020

Having a system to retrieve data from barcode values opens up all sorts of possibilities. For example you can use a phone to photograph a barcode, obtain the value from the image, then instantly retrieve product data, whether it’s for your employees or a customer. Regardless of how you use it, this functionality can be easily implemented with one of our APIs. Here’s how.

First we need to install our API client using this Composer command.

composer require cloudmersive/cloudmersive_barcode_api_client

Next we shall call our function, as you see here.

<?phprequire_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 valuetry {$result = $apiInstance->barcodeLookupEanLookup($value);print_r($result);} catch (Exception $e) {echo 'Exception when calling BarcodeLookupApi->barcodeLookupEanLookup: ', $e->getMessage(), PHP_EOL;}?>

All done! Yup, it really is that simple. Want more easy solutions like this? Well, this same API client holds the keys to many other functions, such as name validation and IP geolocation, all with simple function calls like this one.

--

--

Cloudmersive

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