Skip to content
TORNLIFE More

ItemIDs

Started by theCodingBro [2086910] on in Tools & Userscripts.

3 replies · 92 views · thread synced · 3 days ago · View on torn.com
About this thread

Posts archived: 4 / 4 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
4
Discussion span
→
People posting
2
Likes on archived posts
1
Posts by staff, officers and moderators
1
Authority score
53 / 100
Historical score
13 / 100
Story score
23 / 100
Engagement score
41 / 100

Most-liked replies

theCodingBro [2086910]
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?
theCodingBro [2086910]
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);