Hey guys. Working on a tool, and just trying to save myself a little time here.
Does anyone have a list of itemID:itemName key value pairs by any chance?
Ahh, I completely missed that. Brilliant, thank you very much!
In the hopes of it being useful to others, here's something I made that creates an object just with itemID : itemName keyvalues.
const yourAPIKey
let itemIDDictionary = {};
let xhr = new XMLHttpRequest();
xhr.open("GET", `https://api.torn.com/torn/?selections=items&key=${yourAPIKey}`, true);
xhr.addEventListener('load', function() {
let data = JSON.parse(xhr.responseText);
for(let eachItem in data.items) {
let itemID = eachItem;
itemIDDictionary[itemID] = data.items[eachItem].name;
}
});
xhr.send();
console.log(itemIDDictionary); // prints out the above dictionary to the console. Do what you want with it other than logging of course.
Also, the other way around is useful if you want to do a lookup by item name instead:
let itemIDDictionary = {};
let xhr = new XMLHttpRequest();
xhr.open("GET", `https://api.torn.com/torn/?selections=items&key=`, true);
xhr.addEventListener('load', function() {
let data = JSON.parse(xhr.responseText);
for(let eachItem in data.items) {
let itemID = eachItem;
itemIDDictionary[data.items[eachItem].name] = itemID;
}
});
xhr.send();
console.log(itemIDDictionary);