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));
{
"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": []
}
]
}
if(result.code == "200") {
var products = JSON.parse(result.body);
var product = products.products[0];
entry["title"] = product.product_name;
entry["image"] = product.images;
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
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?