API Services v2

We have three API services available for use in your own applications. You can use our XML or JSON API to query the database for information on an item, and, thanks to your suggestions, you can also use our new cURL API to insert an item into the database.

An API key is required to use the service. You can get an API key for free by signing up.

While this service is free to those who wish to use it, please remember that we have to pay to keep this service alive. If you are using the API for commercial purposes, we ask that you may provide us with a donation to keep this service running.

Disclaimer: This API service provides no guarantee on uptime, or the validity of the information returned.

 

 

 

API changes:

February 17th, 2014:
• UPC Codes must be entered exactly. Partial codes will no longer be accepted.

March 24, 2014:
• A new quota has been added to the API interface. The daily quota is 1000. You can contact us to get this limit raised.

November 24, 2014:
• You are now able to purchase additional API requests through the API control panel.
• Free API access will be subjected to restrictions during times of high server load.

 

 

 

Using the XML API

Our XML API service is located at the following URL:
http://api.upcdatabase.org/xml/APIKEY/CODE

Output if the code exists:

    <?xml version="1.0" encoding="ISO-8859-1"?>
<output xmlns="http://upcdatabase.org/">
    <valid>true</valid>
    <number>0111222333446</number>
    <itemname>UPC Database Testing Code</itemname>
    <alias>Testing Code</alias>
    <description>http://upcdatabase.org/code/0111222333446</description>
    <avgprice>123.45</avgprice>
    <rate_up>2</rate_up>
    <rate_down>0</rate_down>
</output>

If the no price is found, or a feild does not contain data, it will be empty.

Output if the code does not exists:

<?xml version="1.0" encoding="ISO-8859-1"?>
<output xmlns="http://upcdatabase.org/">
<valid>false</valid>
<error>301</error>
<reason>Code does not exist!</reason>
</output>

Similar errors occur if the API length is incorrect or does not exist, or if the code is non-numeric.

Error codes:

101 - API Key length is incorrect
105 - API Key incorrect
199 - No more API requests remaining
201 - You did not enter a code
205 - The code you entered was non-numeric
301 - Code does not exist

500 - High server load

 

 

 

Using the JSON API

Our JSON API service is located at the following URL:
http://api.upcdatabase.org/json/APIKEY/CODE

Output if the code exists:

    {"valid":"true","number":"0111222333446","itemname":"UPC Database Testing Code","alias":"Testing Code","description":"http:\/\/upcdatabase.org\/code\/0111222333446","avg_price":"123.45","rate_up":0,"rate_down":0}
    

Output if the code does not exists:

{"valid":"false","reason":"Code not found in database."}

 

 

 

Using the cURL API to insert codes

Our cURL API allows users to submit codes by POSTing them to the following URL:
http://api.upcdatabase.org/submit/curl.php

Sample code (PHP):

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => 'http://api.upcdatabase.org/submit/curl.php',
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => http_build_query(array(
        'upc' => '0000000000000',
        'mrsp' => '0.00',
        'apikey' => 'YOURAPIKEYGOESHERE',
        'title' => 'Title of product',
        'alias' => 'Title alias',
        'description' => 'Optional lengthy description of product.',
        'unit' => 'Per case'
))));
$server_output = curl_exec($ch);
curl_close($ch);

if( $server_output == 'OK' ) {
    echo "Everything went alright!";
} else {
    echo "An error occured: ", $server_output;
}

Possible outputs:

There are various human-readable errors that our script can produce if there is an error.

Code length incorrect -The UPC code is the wrong length.
Invalid API key -The API you entered contains spaces, or is not 32 chars long.
Title must be 3 or more characters
Ailias must be under 20 characters
Item already exists -The UPC you entered already exists.
OK -The system accepted your code and added it to the database.
API key not found -The API key you entered does not belong to anyone.
An unknown problem has occured. -Should never happen.