PHP Barcode API Lookup

Many applications require product data, and given the popularity of PHP as a programming language there's no shortage of PHP-based apps and tools that need access to a broad array of product information.

Go-UPC is an ideal solution for such applications — especially those that need to scan barcodes — as our database is vast, can provide advanced product information, and includes products in many niches. Provide any UPC or EAN number and (if the product is known) you'll get back a product name, image, description, and more.

Example API Code

Find below sample PHP code that interacts with our API to look up a product by its UPC. In the sample we echo product name, description, and image URL after getting a result.

NOTE: This example requires the PHP cURL extension.

<?php

$product_code = '9781492054139';
$api_key = 'YOUR_GO_UPC_API_KEY';

$api_base_url = 'https://go-upc.com/api/v1/code/';
$url = $api_base_url . $product_code;

$ch = curl_init();

$data = get_product_data($url, $api_key, $ch);

$product_data = json_decode($data);

var_dump($product_data);

$product_name = $product_data->product->name;
$product_description = $product_data->product->description;
$product_image = $product_data->product->imageUrl;

?>

<p><strong>Product Name:</strong> <?php echo $product_name; ?></p>
<p><strong>Product Description:</strong> <?php echo $product_description; ?></p>
<p><strong>Product Image:</strong> <br/> <img src="<?php echo $product_image; ?>" /></p>

<?php

function get_product_data($url, $api_key, $ch) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer ' . $api_key
    ));
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

For further information about interacting with the API and product fields available, please see our documentation.