-
Notifications
You must be signed in to change notification settings - Fork 1
/
autofill_script.js
41 lines (31 loc) · 1.13 KB
/
autofill_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function getAPIdata(term){
var jsonresult = http().get("https://api.upcitemdb.com/prod/trial/lookup?upc=" + term);
if (jsonresult.code == 200){
var name = JSON.parse(jsonresult.body)["items"][0]["title"];
var details = JSON.parse(jsonresult.body)["items"][0]["description"];
var model = JSON.parse(jsonresult.body)["items"][0]["model"];
//Todo: make these into different fields
var extra = "brand :"+ JSON.parse(jsonresult.body)["items"][0]["brand"] +
"color: " + JSON.parse(jsonresult.body)["items"][0]["color"] +
"size: " + JSON.parse(jsonresult.body)["items"][0]["size"] +
"dimension: " + JSON.parse(jsonresult.body)["items"][0]["dimension"] +
"weight: " + JSON.parse(jsonresult.body)["items"][0]["weight"];
var stuff = new Object();
var lst = [];
stuff["title"] = name;
stuff["description"] = details + extra;
stuff["model"] = model;
lst.push(stuff);
return lst;
} else {
var name = "ERROR with getting info from api!";
var stuff = new Object();
var lst = [];
stuff["title"] = name;
stuff["description"] = name;
stuff["model"] = name;
lst.push(stuff);
return lst;
}
}
result(getAPIdata(query));