
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
torn-api-wrapper
Advanced tools
A wrapper to integrate with the Torn API. Completely type-safe.
In this section I will show you how to install and use the wrapper.
It is possible to pass one apiKey:string or apiKey[] to the constructor. A random key is selected from the array. If you pass an array of keys, the wrapper will automatically remove the key if the current key is invalid.
const TornApi = require('torn-api-wrapper').default
const api = new TornApi('YOUR_API_KEY') // Using a single key
const apiPool = new TornApi(['KEY1', 'KEY2', 'KEY3']) // Using a pool of keys
const getBazaarItems = async () => {
const bazaar = await api.market.bazaar.getItems(206)
if (bazaar) {
console.log(bazaar)
} else {
console.log(api.error)
}
}
getBazaarItems()
Install the wrapper as a dev dependency via NPM or yarn.
npm i torn-api-wrapper -d
yarn add torn-api-wrapper -D
The wrapper was built to be as close as possible to the Torn Api, making development as intuitive as possible. One of the 7 sections is always called up first, followed by subcategories and then helper functions.
const market = await api.market.itemmarket.getItems(206)
const bazaar = await api.market.bazaar.getItems(206)
The main class api contains a error property. This property is updated with every request. If an error occurs, the error is stored in the error property. The error object contains the following properties: code and message. The code property is the error code of the Torn API. The message property is the error message of the Torn API. The requested data is null if an error occurs.
const bazaar = await api.market.bazaar.getItems(206)
// Way 1 - With error handling
if (api.error) {
console.log(api.error)
// { code: 2, message: 'Incorrect key', apiKey: 'YOUR_API_KEY' }
} else {
console.log(bazaar)
}
// Way 2 - No error handling
if (bazaar) {
console.log(bazaar)
}
addKey(key: string)Adds a key to the key pool
api.addKey('YOUR_API_KEY')
removeKey(key: string)Removes a key from the key pool
api.removeKey('YOUR_API_KEY')
checkIfKeyIsValid(key: string): Promise<number | null>Checks if a key is valid. Returns the key level if it is valid, otherwise null
await api.checkIfKeyIsValid('YOUR_API_KEY')
if (api.error) {
console.log(api.error)
// { code: 2, message: 'Incorrect key' }
} else {
console.log(bazaar)
}
getLowestListing(itemId: number)Returns the lowest listing for the given itemId. Possible types: bazaar, itemmarket
const lowestListing = await api.market.getLowestListing(206)
// { type: 'bazaar', cost: 842495, quantity: 6, total_cost: 5054970 }
getItems(itemId: number, limit?: number)Returns a list of bazaar listings for the given itemId
const bazaar = await api.market.bazaar.getItems(206)
// [
// { ID: 73075318, cost: 837000, quantity: 50 },
// { ID: 49697817, cost: 842700, quantity: 2 },
// ...
// ]
getItems(itemId: number, limit?: number)Returns a list of itemmarket listings for the given itemId
const itemmarket = await api.market.itemmarket.getItems(206)
// [
// { ID: 203569084, cost: 840000, quantity: 1 },
// { ID: 203569089, cost: 840000, quantity: 1 },
// ...
// ]
getPoints()Returns a object of points market items with there ids
const pointsmarket = await api.market.pointsmarket.getPoints()
// {
// '14686258': { cost: 45870, quantity: 25, total_cost: 1146750 },
// '14686272': { cost: 45850, quantity: 2000, total_cost: 91700000 },
// ...
// }
getPointsWithoutIds()Returns a object of points market items with there ids
const pointsmarket = await api.market.pointsmarket.getPoints()
// [
// { cost: 45870, quantity: 25, total_cost: 1146750 },
// { cost: 45870, quantity: 25, total_cost: 1146750 },
// ...
// ]
getItems(itemId?: number[])Retrieves the details of an item
const itemDetails = await api.torn.items.getItemDetails([206, 207])
// {
// "206": {
// "name": "Xanax",
// "description": "Increases one's energy.",
// "effect": "Increases energy by 250 and happiness by 75. Includes side effects.",
// "requirement": "",
// "type": "Drug",
// "weapon_type": null,
// "buy_price": 0,
// "sell_price": 0,
// "market_value": 841051,
// "circulation": 4841871,
// "image": "https://www.torn.com/images/items/206/large.png"
// },
// "207": {
// "name": "Ms Torn Crown '07",
// "description": "Awarded to Vixen_ [140202] for winning the Miss Torn City awards 2007!",
// "effect": "",
// "requirement": "",
// "type": "Collectible",
// "weapon_type": null,
// "buy_price": 0,
// "sell_price": 0,
// "market_value": 0,
// "circulation": 1,
// "image": "https://www.torn.com/images/items/207/large.png"
// }
getItemValue(itemId: number)Retrieves the value of an item
const itemValue = await api.torn.items.getItemValue(206)
// 842652
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
FAQs
A wrapper to integrate with the Torn API. Completely type-safe.
The npm package torn-api-wrapper receives a total of 16 weekly downloads. As such, torn-api-wrapper popularity was classified as not popular.
We found that torn-api-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.