Barcode Autofill Lookup for Retail Items?

506 views
Skip to first unread message

Darrell Latta

unread,
Oct 24, 2018, 2:26:07 PM10/24/18
to mementodatabase
Hi.  New to Memento and I am in process of converting my Home Inventory, Music Collection, DVD collection etc. over to Memento.  The one challenge I am encountering is Barcode Lookups on Retail Items purchased for my home inventory (ie. electronics, appliances, personal items, etc.).  The old App I was using (inventory Droid) used to be able to scan just about any UPC barcode and then automatically fill in the basics of the items, saving a lot of manual entries.  Memento seems to have this capability out of the box for CD & Books as there are built in Data Sources to set up under Autofill, however there is nothing similar for other types of Retail Purchases (either by Barcode or Title)??  I know that there is the capability of creating a Custom Source via JavaScript and while tech savvy I am not a JavaScript programmer so don't even know where to start with that or what sites to pull data from.  My questions are:
Are there other Default Data Sources that can be added or invoked to do this?
  • Is there a Library of Custom Scripts written by the Community that contains this or similar Sources?
  • Do any of the members out there have a Sample script that I could incorporate or modify to meet my needs?
I have the latest Memento version along with the Pro License and it is a far superior App to what I have used in the past and while I will continue to use it either way if I could add this ability to my setup I would be a very happy camper.  Any help or thoughts would be appreciated.  Thanks.

Darrell...

Warz Voluntarist

unread,
Feb 26, 2019, 10:20:26 AM2/26/19
to mementodatabase
Maybe you resolved this by now, but I recently started testing Memento Database and looked for a quick solution to this issue as well and was surprised to find there's no official script out there (or is there?). But eventually I found a script by a guy in this google group that worked, here it is with a small modification. You need barcodelookup API key to use this script and that will cost money. But if there's a free solution out there this script could be modified for that. 

Once you scan barcode, this script will send a HTTP request to barcodelookup.com API and use that information to automatically fill out:
- Title
- Description
(you can modify the script to fill out other fields too - try accessing the API url directly to see all fields available.)

To setup autofill script in your Memento Database App go to the library you want this script in and go to:
Menu -> Edit library -> Autofill -> Click the plus -> By barcode -> Custom source

Then open script editor and paste this script there:

function getAPIdata(id) {
 
var results = [];
 
var entry = new Object();
 
const api_key = "YOUR_API_KEY";
 
const url = "https://api.barcodelookup.com/v2/products?barcode="+id+"&formatted=y&key=" + api_key;
 
var result = http().get(url);
 
if(result.code == "200") {
     
var products = JSON.parse(result.body);
     
var product = products.products[0];
     entry
["title"] = product.product_name;
     entry
["description"] = product.description;
 
} else if (result.code == "429") {
     entry
["title"] = "Too many requests. Try again later";
 
} else {
   entry
["title"] = "Error";
 
}
  results
.push(entry);
 
return entry;
}
result
(getAPIdata(query));

You obviously will need to replace "YOUR_API_KEY" with your own. 

Once you've pasted the script, save and go back to the autofill rules page, click the plus and add rule for each field. In this case we will add one for title:
Point out the object property returned by the script: title 
Save in input field: Item name

And add another one for description:
Point out the object property returned by the script: description
Save in input field: Description

Save. It should now work. Try scan something.

The Bowlands

unread,
Feb 26, 2019, 3:20:24 PM2/26/19
to mementodatabase
This is awesome and it worked for me right off.......somewhat by luck because I don't fully understand what is going on
here - 
if(result.code == "200") {
     
var products = JSON.parse(result.body);
     
var product = products.products[0];
     entry
["title"] = product.product_name;
     entry
["description"] = product.description;
  
} else if (result.code == "429") {
     entry
["title"] = "Too many requests. Try again later";
  
} else {
   entry
["title"] = "Error";

Would you have a moment to explain so I can understand enough to add additional fields like Brand & Images

Thanks in advance.
Ted

Warz Voluntarist

unread,
Feb 26, 2019, 3:41:15 PM2/26/19
to mementodatabase
Sure. I think the easiest way to understand this is to actually look at the data received from the API first. Go to:
Replace the api key with your own and barcode if you want. In this example you'll see something like this:
{
   
"products": [
       
{
           
"barcode_number": "753353002527",
           
"barcode_type": "UPC",
           
"barcode_formats": "UPC 753353002527, EAN 0753353002527",
           
"mpn": "765",
           
"model": "",
           
"asin": "",
           
"product_name": "Seagate IronWolf 10TB NAS HDD - ST10000VN0004",
           
"title": "",
           
"category": "Electronics > Electronics Accessories > Computer Components > Storage Devices > Hard Drive Accessories > Hard Drive Carrying Cases",
           
"manufacturer": "Seagate",
           
"brand": "",
           
"label": "",
           
"author": "",
           
"publisher": "",
           
"artist": "",
           
"actor": "",
           
"director": "",
           
"studio": "",
           
"genre": "",
           
"audience_rating": "",
           
"ingredients": "",
           
"nutrition_facts": "",
           
"color": "",
           
"format": "",
           
"package_quantity": "",
           
"size": "",
           
"length": "",
           
"width": "",
           
"height": "",
           
"weight": "",
           
"release_date": "",
           
"description": "Seagate IronWolf 10TB NAS Hard Drive – Internal 10TB Capacity 3.5” Form Factor 7200 RPM Spindle Speed SATA 6GB/s 256-Bit AES Encryption - ST10000VN0004.",
           
"features": [],
           
"images": [
               
"https://images.barcodelookup.com/7559/75593669-1.jpg"
           
],
           
"stores": [
               
{
                   
"store_name": "MacMall Affiliate Advantage Network",
                   
"store_price": "309.99",
                   
"product_url": "http://www.macmall.com/p/10591971?dpno=40180679&source=zwb12166",
                   
"currency_code": "USD",
                   
"currency_symbol": "$"
               
},
               
{
                   
"store_name": "PCM Affiliate Advantage Network",
                   
"store_price": "309.99",
                   
"product_url": "http://www.pcm.com/referrals/default.asp?store=pcmall&dpno=40180679&source=zwb12165",
                   
"currency_code": "USD",
                   
"currency_symbol": "$"
               
},
               
{
                   
"store_name": "Tiger Direct",
                   
"store_price": "309.99",
                   
"product_url": "http://www.tigerdirect.com/applications/searchtools/item-details.asp?EdpNo=3962411",
                   
"currency_code": "USD",
                   
"currency_symbol": "$"
               
}
           
],
           
"reviews": []
       
}
   
]
}

So line by line here is what the code does:

if(result.code == "200") {

If the http requests returns 200 it means it went OK. Server responded OK (200 = OK)

     var products = JSON.parse(result.body);
     var product = products.products[0];

It will take everything from products field in the api and store it in the product variable. That means you can access all the variables like this:
product.barcode_number, product.barcode_type, product.barcode_formats, product.product_name etc

entry["title"] = product.product_name;

This is the object that will be returned later. You can choose the name here, we chose "title". So basically we're storing the product name into a variable "title" within the object "entry". 
This is where you can add as many lines as you want. Example:
entry["bc_number"] = product.barcode_number;
entry["bc_type"] = product.barcode_type;
entry["brand"] = product.brand;

Once you're done you need to add each field to the rules, example rule:
Point out the object property returned by the script : brand

Image is a special case since there can be multiple images, you'd have to do:
images[0] (0 to get the first image)

entry["image"] = product.images[0];

This is untested, but just explained based on how I think it works.

Hope that helps. I just started looking into this today, so I might be off of some things. 

Warz Voluntarist

unread,
Feb 26, 2019, 4:07:17 PM2/26/19
to mementodatabase
I just tested this also:

entry["image"] = product.images;

and sent it into Photo Field. The image was added. Seems like there is support for an array of images. 

For anyone else who's trying to setup this: 
I forgot to mention in my initial post that you must also enable permissions to do HTTP requests in the library. From the WIKI:
To open a card to set permissions for scripts, open the library triggers list and click the Shield icon on the toolbar. Permissions must be set separately on each device. Permissions are not synchronized between devices.
Network
grants to the script the right to execute HTTP requests

ZipZap

unread,
Jun 13, 2020, 9:42:40 PM6/13/20
to mementodatabase
Can someone recommend an API key, I want to do the same thing that Darrell is doing.

Bill Crews

unread,
Jun 14, 2020, 1:41:23 AM6/14/20
to ZipZap, mementodatabase
The wiki example is fully barcode, but are saying the same method will not work for barcode objects? I've never dealt with barcode, but I think this script should work for a custom data source...

var anotherLib = libByName(“AnotherLib”);          // Replace with yours
var entries = anotherLib.find(query);
var resultArray = [];
for(var i in entries ) {
   var object = {};
   object[“title”] = entries[i].title;
   object[“desc”] = entries[i].description;
   object[“number”] = entries[i].field(“Number”); // Replace with yours
   resultArray.push(object);
   }
result(resultArray);

Warz suggests that the following works...

   entry["image"] = product.images;

I didn't read the entire thread and don't know what entry & product are, but if they are like the objects in the example, it should work. Does it?

Bill Crews

unread,
Jun 14, 2020, 6:37:25 AM6/14/20
to ZipZap, mementodatabase
Oh, did you intend to say entry() instead of entry? If so, you could fix it two ways. Just add the parentheses or the following line before that line...

var entry = entry();

-Bill
Reply all
Reply to author
Forward
0 new messages