Getting Started

Assume you already tried API Explorer. Here is a basic sample for the LookupRequest. For FREE plan, just remove user_key, key_type from the request header and change the endpoint path from /v1 to /trial.

Note: JSON format uses Double Quote \”.


$ curl -X POST -H "user_key: only_for_dev_or_pro" -H "key_type: 3scale" -H "Content-Type: application/json" -H "Accept: application/json" -d "{
  \"upc\": \"4002293401102\"
}" "https://api.upcitemdb.com/prod/v1/lookup"
    
  


#!/usr/bin/perl

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Headers;
use LWP::Debug '+';

$user_key = 'only_for_dev_or_pro';
$endpoint = 'https://api.upcitemdb.com/prod/v1/lookup';

$ua = LWP::UserAgent->new;
# debug request/response
$ua->add_handler("request_send",  sub { shift->dump; return });
$ua->add_handler("response_done", sub { shift->dump; return });
$h = HTTP::Headers->new(
    Content_Type => 'application/json',
    Accept => 'application/json'
    );
#preserve underscore in header name
$HTTP::Headers::TRANSLATE_UNDERSCORE = 0;
$h->header("user_key" => $user_key);
$h->header("key_type" => '3scale');

$url = $endpoint . '?upc=650106303651';
$req = HTTP::Request->new('GET', $url, $h);
$resp = $ua->request($req);

if ($resp->is_success) {
    $msg = $resp->decoded_content;
    print "Resp: $message\n";
} else {
    print "Error " . $resp->code . ": " . $resp->message . "\n";
}
    
  


<?php
$user_key = 'only_for_dev_or_pro';
$endpoint = 'https://api.upcitemdb.com/prod/v1/lookup';

$ch = curl_init();
/* if your client is old and doesn't have our CA certs
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);*/
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "user_key: $user_key",
  "key_type: 3scale"
));

// HTTP GET
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $endpoint.'?upc=4002293401102');
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode != 200)
  echo "error status $httpcode...\n";
else 
  echo $response."\n";
/* if you need to run more queries, do them in the same connection.
 * use rawurlencode() instead of URLEncode(), if you set search string
 * as url query param
 */
sleep(2);
// proceed with other queries
curl_close($ch);
    
  


from urlparse import urlparse
import httplib2 as http
import json

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'user_key': 'only_for_dev_or_pro',
  'key_type': '3scale'
}
ch = http.Http()
lookup = urlparse('https://api.upcitemdb.com/prod/v1/lookup?upc=4002293401102')
resp, content = ch.request(lookup.geturl(), 'GET', '', headers)
data = json.loads(content)
    
  


require 'rest-client'
response = RestClient.post("https://api.upcitemdb.com/prod/v1/lookup",
  { 'upc' => '4002293401102' }.to_json,
  {
    :content_type => :json,
    :accept => :json,
    user_key => 'only_for_dev_or_pro',
    key_type => '3scale'
  }
)
puts "status: #{response.code}"
puts "----headers----"
puts response.headers
puts "----body----"
puts response
    
  


const https = require('https')
var opts = {
  hostname: 'api.upcitemdb.com',
  path: '/prod/v1/lookup',
  method: 'POST',
  headers: {
    "Content-Type": "application/json",
    "user_key": "only_for_dev_or_pro",
    "key_type": "3scale"
  }
}
var req = https.request(opts, function(res) {
  console.log('statusCode: ', res.statusCode);
  console.log('headers: ', res.headers);
  res.on('data', function(d) {
    console.log('BODY: ' + d);
  })
})
req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
})
req.write('{ "upc": "4002293401102" }')
// other requests
req.end()
    
  


using System;
using RestSharp;
using Newtonsoft.Json;
using Microsoft.CSharp;

namespace UpcClient
{
  class MainClass
  {
    public static void Main(string[] args)
    {
      var user_key = "only_for_dev_or_pro";

      var client = new RestClient("https://api.upcitemdb.com/prod/v1/");
      // lookup request with GET
      var request = new RestRequest("lookup", Method.GET);
      request.AddHeader("key_type", "3scale");
      request.AddHeader("user_key", user_key);

      request.AddQueryParameter("upc", "674785680773");
      IRestResponse response = client.Execute(request);
      Console.WriteLine("response: " + response.Content);
      // parsing json
      var obj = JsonConvert.DeserializeObject(response.Content);
      Console.WriteLine("offset: " + obj["offset"]);
    }
  }
}