### Storage Implementation Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Provides an example of how to implement custom storage for the trade offer manager by listening to 'save' and 'read' events. This allows data to be stored in systems other than the default file system. ```APIDOC ## Storage Implementation ### Description Implement custom storage for the trade offer manager by listening to 'save' and 'read' events. This allows data to be stored in systems other than the default file system. ### Events #### save - **filename** (string) - The name of the file to save. - **contents** (Buffer) - The file contents to save. - **callback** (function) - A function to call upon completion or error. Takes a single error argument. #### read - **filename** (string) - The name of the file to read. - **callback** (function) - A function to call upon completion or error. Takes an error argument and a Buffer argument. ### Request Example ```javascript manager.storage.on('save', function(filename, contents, callback) { s// Your save logic here callback(err); }); manager.storage.on('read', function(filename, callback) { // Your read logic here callback(null, file); }); ``` ``` -------------------------------- ### Instantiate TradeOfferManager with Steam Client Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Instantiate the TradeOfferManager, optionally integrating with a node-steam client for real-time polling. Ensure you have the correct node-steam version installed. ```javascript // Steam integration is optional and is only used for instant polling // === FOR node-steam 0.6.x === var Steam = require('steam'); var client = new Steam.SteamClient(); // === END FOR node-steam 0.6.x === // === FOR node-steam 1.0.x AND Steam.SteamUser === var Steam = require('steam'); var connection = new Steam.SteamClient(); var client = new Steam.SteamUser(connection); // === END FOR node-steam 1.0.x AND Steam.SteamUser === // === FOR node-steam-user === var SteamUser = require('steam-user'); var client = new SteamUser(); // === END FOR node-steam-user === var TradeOfferManager = require('steam-tradeoffer-manager'); var manager = new TradeOfferManager({ "steam": client, "domain": "example.com", // Fill this in with your own domain "language": "en" }); ``` -------------------------------- ### Send Trade Offer with Items Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Complete example for sending a trade offer with items from your inventory to a specific user via their trade URL. Includes setting a message, custom data, and handling offer status and confirmations. ```javascript // Complete example: Send items to a trade partner manager.getInventoryContents(730, 2, true, function(err, inventory) { if (err) { console.log("Error loading inventory:", err); return; } if (inventory.length === 0) { console.log("No items to trade"); return; } // Create offer to a user via trade URL let offer = manager.createOffer("https://steamcommunity.com/tradeoffer/new/?partner=46143802&token=KYworVTM"); // Add all inventory items offer.addMyItems(inventory); // Set a message offer.setMessage("Here are some items for you!"); // Store custom data with the offer offer.data('purpose', 'donation'); offer.data('timestamp', Date.now()); // Set custom cancel time for this offer (10 minutes) offer.data('cancelTime', 600000); // Send the offer offer.send(function(err, status) { if (err) { console.log("Error sending offer:", err.message); if (err.eresult) { console.log("EResult:", TradeOfferManager.EResult[err.eresult]); } if (err.cause) { // TradeBan, NewDevice, TargetCannotTrade, OfferLimitExceeded, ItemServerUnavailable console.log("Cause:", err.cause); } return; } console.log("Offer #" + offer.id + " sent, status:", status); if (status === 'pending') { // Offer needs mobile/email confirmation community.acceptConfirmationForObject("identitySecret", offer.id, function(err) { if (err) { console.log("Error confirming:", err); } else { console.log("Offer confirmed!"); } }); } }); }); ``` -------------------------------- ### Load Partner's Inventory Contents Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Loads a trading partner's inventory for a specific application and context, enabling browsing of their tradable items. This example demonstrates loading CS:GO inventory and adding items to an offer. ```javascript let offer = manager.createOffer("[U:1:46143802]", "KYworVTM"); // Load partner's CS:GO inventory offer.getPartnerInventoryContents(730, 2, function(err, inventory, currencies) { if (err) { console.log("Error loading partner inventory:", err); return; } console.log("Partner has " + inventory.length + " tradable CS:GO items"); // Find specific items to request let keys = inventory.filter(item => item.market_hash_name === 'CS:GO Case Key'); if (keys.length > 0) { console.log("Found " + keys.length + " keys, requesting first one"); offer.addTheirItems([keys[0]]); // Now add items from our inventory and send manager.getInventoryContents(730, 2, true, function(err, myInventory) { if (err) { console.log("Error:", err); return; } let myCases = myInventory.filter(item => item.type && item.type.includes('Case')); if (myCases.length > 0) { offer.addMyItems([myCases[0]]); offer.send(function(err, status) { console.log(err ? "Error: " + err : "Sent with status: " + status); }); } }); } }); ``` -------------------------------- ### Get Trade Offers by Filter Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Retrieves a list of trade offers based on a specified filter. ```APIDOC ## GET /offers ### Description Retrieves a list of trade offers matching specific criteria. ### Method GET ### Endpoint /offers ### Parameters #### Query Parameters - **filter** (EOfferFilter) - Required - A value from EOfferFilter. - **historicalCutoff** (Date) - Optional - If filter is `ActiveOnly`, offers modified after this date will be returned. ### Response #### Success Response (200) - **sent** (Array) - An array of TradeOffer objects for offers sent by you. - **received** (Array) - An array of TradeOffer objects for offers received by you. #### Error Response - **err** (Error) - An Error object on failure. May contain an `eresult` property. ### Request Example ```javascript // Get all active offers manager.getOffers(EOfferFilter.ActiveOnly, (err, sent, received) => { if (err) { console.error(err); } else { console.log('Sent offers:', sent); console.log('Received offers:', received); } }); // Get offers active or modified after a certain date const cutoffDate = new Date('2023-01-01'); manager.getOffers(EOfferFilter.ActiveOnly, cutoffDate, (err, sent, received) => { // ... }); ``` ``` -------------------------------- ### Find Offers Containing Specific Items (Including Inactive) Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt This example demonstrates how to use `getOffersContainingItems` to search for trade offers, including both active and inactive ones, that contain specific items. This provides a comprehensive view of item involvement in trades. ```javascript let itemsToCheck = [ { appid: 730, contextid: "2", assetid: "123456789" }, { appid: 730, contextid: "2", assetid: "987654321" } ]; // Include inactive offers too manager.getOffersContainingItems(itemsToCheck, true, function(err, sent, received) { if (err) { console.log("Error:", err); return; } console.log("Total offers (including historical) containing items:"); console.log("Sent:", sent.length, "Received:", received.length); }); ``` -------------------------------- ### Get User's Inventory Contents Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Retrieves the contents of the current user's inventory for a specific game. ```APIDOC ## GET /inventory/{appId}/{contextId} ### Description Gets the contents of your own inventory for a specific game and context. ### Method GET ### Endpoint /inventory/{appId}/{contextId} ### Parameters #### Path Parameters - **appid** (number) - Required - The Steam App ID of the game. - **contextid** (string) - Required - The ID of the context within the app. #### Query Parameters - **tradableOnly** (boolean) - Required - `true` to include only tradable items, `false` for all items. ### Response #### Success Response (200) - **inventory** (Array) - An array of the user's inventory items. - **currencies** (Array) - An array of the user's currency items. #### Error Response - **err** (Error) - An Error object on failure. ### Request Example ```javascript // Requires v2.5.0 or later manager.getInventoryContents(440, '2', true, (err, inventory, currencies) => { if (err) { console.error(err); } else { console.log('Inventory:', inventory); console.log('Currencies:', currencies); } }); ``` ``` -------------------------------- ### Get User Inventory Contents Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieves inventory items and currency for a specified app and context. Uses a less rate-limited endpoint. Requires appid, contextid, and a boolean indicating if only tradable items are needed. ```javascript // Get CS:GO inventory (appid: 730, contextid: 2) manager.getInventoryContents(730, 2, true, function(err, inventory, currencies) { if (err) { console.log("Error loading inventory:", err); return; } console.log("Found " + inventory.length + " tradable items"); inventory.forEach(function(item) { console.log("Item:", item.name); console.log(" Asset ID:", item.assetid); console.log(" Market Hash Name:", item.market_hash_name); console.log(" Tradable:", item.tradable); console.log(" Type:", item.type); }); }); ``` ```javascript // Get TF2 inventory (appid: 440, contextid: 2) manager.getInventoryContents(440, 2, false, function(err, inventory, currencies) { if (err) { console.log("Error:", err); return; } // Filter for specific items let keys = inventory.filter(item => item.market_hash_name === 'Mann Co. Supply Crate Key'); console.log("Found " + keys.length + " TF2 keys"); }); ``` -------------------------------- ### Get Trade Offer Token Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieve your account's trade offer token using `getOfferToken`. This token is essential for allowing non-friends to send you trade offers and can be used to construct a full trade URL. ```javascript manager.getOfferToken(function(err, token) { if (err) { console.log("Error getting token:", err); return; } console.log("Your trade token:", token); console.log("Full trade URL: https://steamcommunity.com/tradeoffer/new/?partner=" + manager.steamID.accountid + "&token=" + token); }); ``` -------------------------------- ### Set Steam Web Session Cookies Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Initialize the TradeOfferManager with Steam web session cookies obtained after logging in. This is a prerequisite for performing any trading operations. The callback handles potential errors and confirms successful setup. ```javascript const SteamUser = require('steam-user'); const SteamTotp = require('steam-totp'); let client = new SteamUser(); client.logOn({ accountName: "username", password: "password", twoFactorCode: SteamTotp.getAuthCode("sharedSecret") }); client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies, function(err) { if (err) { console.log("Error setting cookies:", err); if (err.message === 'Access Denied') { console.log("Account may be limited"); } process.exit(1); } console.log("Cookies set, API key:", manager.apiKey); console.log("Logged in as:", manager.steamID.getSteam3RenderedID()); // Ready to trade }); }); ``` ```javascript client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies, "1234", function(err) { if (err) { console.log("Error:", err); return; } console.log("Cookies set with Family View unlocked"); }); }); ``` -------------------------------- ### Get Trade Offer by ID Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Retrieves a specific trade offer using its unique ID. ```APIDOC ## GET /offers/{id} ### Description Gets a TradeOffer object for a specific offer ID. ### Method GET ### Endpoint /offers/{id} ### Parameters #### Path Parameters - **id** (string|number) - Required - The ID of the trade offer. ### Response #### Success Response (200) - **offer** (TradeOffer) - A TradeOffer object for the requested offer. #### Error Response - **err** (Error) - An Error object on failure. May contain an `eresult` property. ### Request Example ```javascript manager.getOffer(offerId, (err, offer) => { if (err) { console.error(err); } else { console.log(offer); } }); ``` ``` -------------------------------- ### Implement Custom Storage Engine for Trade Offers Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Implement custom storage for trade offer data by listening to 'save' and 'read' events. You must call the provided callback function upon completion or error. ```javascript manager.storage.on('save', function(filename, contents, callback) { // filename is the name of the file, as a string // contents is a Buffer containing the file's contents // callback is a function which you MUST call on completion or error, with a single error argument // For example: someStorageSystem.saveFile(filename, contents, function(err) { callback(err); }); }); manager.storage.on('read', function(filename, callback) { // filename is the name of the file, as a string // callback is a function which you MUST call on completion or error, with an error argument and a Buffer argument // For example: someStorageSystem.readFile(filename, function(err, file) { if(err) { callback(err); return; } callback(null, file); }); }); ``` -------------------------------- ### Offer Information and Settings Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOffer Methods for checking item presence, setting offer messages, and setting trade tokens. ```APIDOC ## GET /api/tradeoffer/item/containsItem ### Description Checks if a given item is present in the trade offer. ### Method GET ### Endpoint /api/tradeoffer/item/containsItem ### Parameters #### Query Parameters - **item** (object) - Required - An item object containing `appid`, `contextid`, and `assetid`/`id` properties. ### Request Example ```json { "item": { "appid": 730, "contextid": 2, "assetid": "1234567890" } } ``` ### Response #### Success Response (200) - **contains** (boolean) - `true` if the item is in the offer, `false` otherwise. #### Response Example ```json { "contains": true } ``` ## POST /api/tradeoffer/message/setMessage ### Description Sets the message for an unsent trade offer. ### Method POST ### Endpoint /api/tradeoffer/message/setMessage ### Parameters #### Request Body - **message** (string) - Required - The new message for the offer. Can be an empty string. Maximum 128 characters. ### Request Example ```json { "message": "Hello, let's trade!" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the message was set successfully. #### Response Example ```json { "success": true } ``` ## POST /api/tradeoffer/token/setToken ### Description Sets the access token for sending a trade offer to a non-friend. ### Method POST ### Endpoint /api/tradeoffer/token/setToken ### Parameters #### Request Body - **token** (string) - Required - The access token to use for sending the offer. ### Request Example ```json { "token": "YOUR_ACCESS_TOKEN" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the token was set successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Get Another User's Inventory Contents Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Retrieves the inventory contents of another user for a specific game. ```APIDOC ## GET /users/{steamID}/inventory/{appId}/{contextId} ### Description Retrieves another user's inventory contents for a specific game and context. ### Method GET ### Endpoint /users/{steamID}/inventory/{appId}/{contextId} ### Parameters #### Path Parameters - **steamID** (SteamID|string) - Required - The SteamID of the user. - **appid** (number) - Required - The Steam App ID of the game. - **contextid** (string) - Required - The ID of the context within the app. #### Query Parameters - **tradableOnly** (boolean) - Required - `true` to include only tradable items, `false` for all items. ### Response #### Success Response (200) - **inventory** (Array) - An array of the user's inventory items. - **currencies** (Array) - An array of the user's currency items. #### Error Response - **err** (Error) - An Error object on failure. ### Request Example ```javascript // Requires v2.5.0 or later const userSteamID = '76561198000000001'; // Example SteamID manager.getUserInventoryContents(userSteamID, 440, '2', false, (err, inventory, currencies) => { if (err) { console.error(err); } else { console.log('User Inventory:', inventory); console.log('User Currencies:', currencies); } }); ``` ``` -------------------------------- ### Countering and Duplicating Trade Offers Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Use `offer.counter()` to create a new offer based on an existing one, marking the original as countered. Use `offer.duplicate()` to create an independent copy of an offer. Both methods are useful for modifying or resending offers. ```javascript manager.on('newOffer', function(offer) { // Counter an offer with modified terms if (offer.itemsToReceive.length > 0 && offer.itemsToGive.length === 0) { console.log("Received gift offer, countering with a request"); let counterOffer = offer.counter(); // Keep what they're giving // Add something we want from them offer.getPartnerInventoryContents(730, 2, function(err, inventory) { if (err || inventory.length === 0) { console.log("Can't load inventory, declining original"); offer.decline(); return; } counterOffer.addTheirItems([inventory[0]]); counterOffer.setMessage("Thanks, but could you add this too?"); counterOffer.send(function(err, status) { if (err) { console.log("Error sending counter:", err); } else { console.log("Counter offer sent:", counterOffer.id); // Original offer is now in Countered state } }); }); } }); // Duplicate an offer to resend it manager.getOffer("1234567890", function(err, offer) { if (err) { console.log("Error:", err); return; } if (offer.state === TradeOfferManager.ETradeOfferState.Declined) { console.log("Offer was declined, creating duplicate to try again"); let newOffer = offer.duplicate(); newOffer.setMessage("Please reconsider!"); newOffer.send(function(err, status) { console.log(err ? "Error: " + err : "New offer sent: " + newOffer.id); }); } }); ``` -------------------------------- ### Get Partner Inventory Contents Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOffer Retrieves the contents of a trading partner's inventory for a specific app and context. Requires v2.5.0 or later. ```javascript getPartnerInventoryContents(appid, contextid, callback) ``` -------------------------------- ### Create Trade Offer with Different Partner Identifiers Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Create a new trade offer by providing the partner's SteamID as a string, a SteamID object, or a trade URL. A trade token can also be provided if available. ```javascript var offer = manager.createOffer("[U:1:46143802]"); // no trade token provided, must be friends or must use offer.setToken() before sending var offer = manager.createOffer(new TradeOfferManager.SteamID("76561198006409530"), "KYworVTM"); // trade token provided var offer = manager.createOffer("https://steamcommunity.com/tradeoffer/new/?partner=46143802"); // SteamID provided but no trade token var offer = manager.createOffer("https://steamcommunity.com/tradeoffer/new/?partner=46143802&token=KYworVTM"); // SteamID and trade token both provided ``` -------------------------------- ### GET /offers Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieves multiple trade offers matching a filter criteria. Can retrieve active offers, all offers, or offers modified after a certain date. ```APIDOC ## GET /offers ### Description Retrieves multiple trade offers matching a filter criteria. Can retrieve active offers, all offers, or offers modified after a certain date. ### Method GET ### Endpoint /offers ### Parameters #### Query Parameters - **filter** (EOfferFilter) - Required - Specifies the filter for offers (e.g., ActiveOnly, All). - **cutoffDate** (Date) - Optional - If provided, retrieves offers active or modified after this date. ### Request Example ```javascript // Get all active offers manager.getOffers(TradeOfferManager.EOfferFilter.ActiveOnly, function(err, sent, received) { if (err) { console.log("Error:", err); return; } console.log("Active sent offers:", sent.length); console.log("Active received offers:", received.length); }); // Get offers with historical cutoff (offers active OR modified after date) let cutoffDate = new Date(Date.now() - 24 * 60 * 60 * 1000); // 24 hours ago manager.getOffers(TradeOfferManager.EOfferFilter.ActiveOnly, cutoffDate, function(err, sent, received) { if (err) { console.log("Error:", err); return; } console.log("Found", sent.length + received.length, "offers from last 24 hours"); }); // Get all offers (including historical) manager.getOffers(TradeOfferManager.EOfferFilter.All, function(err, sent, received) { if (err) { console.log("Error:", err); return; } let acceptedOffers = [...sent, ...received].filter( offer => offer.state === TradeOfferManager.ETradeOfferState.Accepted ); console.log("Total accepted offers:", acceptedOffers.length); }); ``` ### Response #### Success Response (200) - **sent** (Array) - An array of sent trade offers. - **received** (Array) - An array of received trade offers. #### Response Example ```json { "sent": [ { "id": "1234567890", "partner": { "getSteam3RenderedID": () => "[STEAMID]" }, "itemsToGive": [], "itemsToReceive": [], "state": 7 // Accepted } ], "received": [ { "id": "0987654321", "partner": { "getSteam3RenderedID": () => "[STEAMID]" }, "itemsToGive": [], "itemsToReceive": [], "state": 7 // Accepted } ] } ``` ``` -------------------------------- ### Handle New Incoming Trade Offers Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Listen for the 'newOffer' event to process incoming trade offers. This event provides the offer object, allowing you to log details like offer ID, partner, and item counts. ```javascript manager.on('newOffer', function(offer) { console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID()); console.log("Items to give:", offer.itemsToGive.length); console.log("Items to receive:", offer.itemsToReceive.length); }); ``` -------------------------------- ### Get Inventory Contents Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieves the contents of your own Steam inventory for a specific application and context. This method utilizes the newer, less rate-limited inventory endpoint. ```APIDOC ## getInventoryContents ### Description Retrieves the contents of your own Steam inventory for a specific app and context. Uses the newer inventory endpoint which is less rate-limited. Returns arrays of inventory items and currency items as EconItem objects. ### Method `getInventoryContents` ### Parameters #### Path Parameters - **appId** (number) - Required - The AppID of the game. - **contextId** (string | number) - Required - The context ID of the inventory. - **tradableOnly** (boolean) - Required - Whether to only return tradable items. - **callback** (function) - Required - A callback function that receives an error object (if any), an array of inventory items, and an array of currency items. ### Request Example ```javascript // Get CS:GO inventory (appid: 730, contextid: 2) manager.getInventoryContents(730, 2, true, function(err, inventory, currencies) { if (err) { console.log("Error loading inventory:", err); return; } console.log("Found " + inventory.length + " tradable items"); inventory.forEach(function(item) { console.log("Item:", item.name); console.log(" Asset ID:", item.assetid); console.log(" Market Hash Name:", item.market_hash_name); console.log(" Tradable:", item.tradable); console.log(" Type:", item.type); }); }); // Get TF2 inventory (appid: 440, contextid: 2) manager.getInventoryContents(440, 2, false, function(err, inventory, currencies) { if (err) { console.log("Error:", err); return; } // Filter for specific items let keys = inventory.filter(item => item.market_hash_name === 'Mann Co. Supply Crate Key'); console.log("Found " + keys.length + " TF2 keys"); }); ``` ``` -------------------------------- ### Get User Details for Trade Offers Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieves escrow and profile information for both parties involved in a trade. Useful for checking trade holds and user status before sending an offer. ```javascript let offer = manager.createOffer("https://steamcommunity.com/tradeoffer/new/?partner=46143802&token=KYworVTM"); offer.getUserDetails(function(err, me, them) { if (err) { console.log("Error getting user details:", err); console.log("This might indicate you can't trade with this user"); return; } console.log("My details:"); console.log(" Name:", me.personaName); console.log(" Escrow days:", me.escrowDays); console.log(" Avatar:", me.avatarFull); console.log("\nTheir details:"); console.log(" Name:", them.personaName); console.log(" Escrow days:", them.escrowDays); console.log(" On probation:", them.probation); console.log(" Avatar:", them.avatarFull); // Check if trade will be held let maxEscrow = Math.max(me.escrowDays, them.escrowDays); if (maxEscrow > 0) { console.log("\nWARNING: Trade will be held for", maxEscrow, "days"); } if (them.probation) { console.log("WARNING: User is on trade probation"); } }); ``` -------------------------------- ### Initialize TradeOfferManager and SteamID Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/Home Demonstrates how to require the TradeOfferManager module and access its SteamID property to create a SteamID object. Ensure 'steamid' is added to your package.json if requiring it separately. ```javascript var TradeOfferManager = require('steam-tradeoffer-manager'); var SteamID = TradeOfferManager.SteamID; var sid = new SteamID('[U:1:46143802]'); // do something with it... ``` -------------------------------- ### Save Poll Data Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt The 'pollData' event is emitted when new poll data is available. It's recommended to save this data, for example, to a JSON file, for later use or analysis. ```javascript manager.on('pollData', function(pollData) { require('fs').writeFileSync('polldata.json', JSON.stringify(pollData)); }); ``` -------------------------------- ### Get Trade Offer Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieves a specific trade offer by its unique ID. The returned TradeOffer object contains comprehensive details about the offer, including its state, items involved, and metadata. ```APIDOC ## getOffer ### Description Retrieves a specific trade offer by its ID. Returns a TradeOffer object with complete details including items, state, and metadata. ### Method `getOffer` ### Parameters #### Path Parameters - **offerID** (string) - Required - The ID of the trade offer to retrieve. - **callback** (function) - Required - A callback function that receives an error object (if any) and the TradeOffer object. ### Request Example ```javascript manager.getOffer("1234567890", function(err, offer) { if (err) { console.log("Error getting offer:", err); if (err.eresult) { console.log("EResult:", TradeOfferManager.EResult[err.eresult]); } return; } console.log("Offer #" + offer.id); console.log(" Partner:", offer.partner.getSteam3RenderedID()); console.log(" State:", TradeOfferManager.ETradeOfferState[offer.state]); console.log(" Is our offer:", offer.isOurOffer); console.log(" Message:", offer.message); console.log(" Created:", offer.created); console.log(" Expires:", offer.expires); console.log(" Items to give:", offer.itemsToGive.length); console.log(" Items to receive:", offer.itemsToReceive.length); offer.itemsToReceive.forEach(function(item) { console.log(" -", item.name, "(", item.assetid, ")"); }); }); ``` ``` -------------------------------- ### TradeOfferManager Constructor and Options Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Instantiate the TradeOfferManager and configure its options. Steam integration is optional and used for instant polling. ```APIDOC ## Constructor([options]) - `options` - Optional. An object containing any or all of the following options ### Options #### steam Optional. See [Steam Integration](#steam-integration) below. #### community Optional. A [`node-steamcommunity`](https://github.com/DoctorMcKay/node-steamcommunity) instance of v3.19.1 or later to use. If not provided, one will be created internally automatically. #### domain Required if `useAccessToken` is true. Your domain name. #### useAccessToken Optional. If true, the manager will use an access token for authentication instead of cookies. #### language Optional. The language code for the trade offer manager (e.g., 'en'). Defaults to 'en'. #### pollInterval Optional. The interval in milliseconds between polls for new trade offers. Defaults to 30000. #### minimumPollInterval Optional. The minimum interval in milliseconds between polls. Defaults to 1000. #### pollFullUpdateInterval Optional. The interval in milliseconds between full updates of the offer list. Defaults to 300000. #### cancelTime Optional. The time in milliseconds after which an offer will be canceled if it's not accepted or declined. Defaults to 21600000 (6 hours). #### pendingCancelTime Optional. The time in milliseconds after which a pending offer will be canceled. Defaults to 60000 (1 minute). #### cancelOfferCount Optional. The maximum number of offers to cancel at once. Defaults to 10. #### cancelOfferCountMinAge Optional. The minimum age in milliseconds for an offer to be considered for cancellation. Defaults to 300000 (5 minutes). #### globalAssetCache Optional. If true, enables a global asset cache. Defaults to true. #### assetCacheMaxItems Optional. The maximum number of items to store in the asset cache. Defaults to 10000. #### assetCacheGcInterval Optional. The interval in milliseconds for garbage collection of the asset cache. Defaults to 3600000 (1 hour). #### pollData Optional. An object containing data to initialize the polling state. #### dataDirectory Optional. The directory to store poll data. If not provided, poll data will not be saved. #### gzipData Optional. If true, poll data will be gzipped before saving. Defaults to true. #### savePollData Optional. If true, poll data will be saved automatically. Defaults to true. ### Steam Integration Optional and is only used for instant polling. Examples provided for different `node-steam` versions. ``` -------------------------------- ### Initialize TradeOfferManager with Options Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Instantiate TradeOfferManager with various configuration options for Steam integration, polling, and offer management. Ensure to restore poll data from a previous session if available. ```javascript const TradeOfferManager = require('steam-tradeoffer-manager'); const SteamUser = require('steam-user'); const FS = require('fs'); let client = new SteamUser(); let manager = new TradeOfferManager({ steam: client, // Optional: SteamUser instance for instant notifications domain: "example.com", // Domain for API key registration language: "en", // Language for item descriptions pollInterval: 30000, // Poll every 30 seconds (default) minimumPollInterval: 1000, // Minimum time between polls cancelTime: 600000, // Auto-cancel sent offers after 10 minutes pendingCancelTime: 300000, // Auto-cancel unconfirmed offers after 5 minutes cancelOfferCount: 30, // Cancel oldest if more than 30 active offers cancelOfferCountMinAge: 60000, // Only cancel offers older than 1 minute useAccessToken: true, // Use access token instead of API key globalAssetCache: true, // Share asset cache across instances assetCacheMaxItems: 500, // Max cached item descriptions dataDirectory: './data', // Where to store poll data and cache savePollData: true // Auto-save poll data to disk }); // Restore poll data from previous session if (FS.existsSync('polldata.json')) { manager.pollData = JSON.parse(FS.readFileSync('polldata.json').toString('utf8')); } ``` -------------------------------- ### GET /getExchangeDetails Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOffer Retrieves detailed information for the items exchanged in a trade offer. This method can be used for any trade offer with a defined `tradeID`, including those in escrow or that have failed. Requires v2.6.0 or later. ```APIDOC ## GET /getExchangeDetails ### Description Gets detailed information for the items exchanged in this trade, including old and new asset IDs. This can be called for any trade offer that has a `tradeID` property defined that isn't `null`, including those that are in escrow or have failed. If you pass true to `getDetailsIfFailed`, it is vitally important that you check the `status` to be sure that the trade hasn't failed or been rolled back before processing the trade as having completed. ### Method GET ### Endpoint /getExchangeDetails ### Parameters #### Query Parameters - **getDetailsIfFailed** (boolean) - Optional - If `false` and the trade's state is anything but `Complete`, `InEscrow`, or `EscrowRollback`, then the callback will report an error instead of returning the data to you. Defaults to `false`. - **callback** (function) - Required - A callback to be invoked when complete. - **err** (Error) - An `Error` object on failure, or `null` on success - **status** (ETradeStatus) - The status of this trade, which differs from the trade **offer** state. One of the values from the [`ETradeStatus`](https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/blob/master/resources/ETradeStatus.js) enum, which is accessible via `TradeOfferManager.ETradeStatus`. - **tradeInitTime** (Date) - A `Date` object representing when Steam began processing the item exchange. If this trade was held, then this is the time when Steam began removing items from both parties' inventories, i.e. the time when the trade went into escrow. - **receivedItems** (Array) - An array of `EconItem` objects for items you received in this trade. - **sentItems** (Array) - An array of `EconItem` objects for items you lost in this trade. ### Request Example ```javascript // Assuming 'manager' is an instance of TradeOfferManager and 'trade' is a TradeOffer object trade.getExchangeDetails(false, (err, status, tradeInitTime, receivedItems, sentItems) => { if (err) { console.error('Error getting exchange details:', err); return; } console.log('Trade Status:', status); console.log('Received Items:', receivedItems); console.log('Sent Items:', sentItems); }); ``` ### Response #### Success Response (200) - **status** (ETradeStatus) - The status of the trade offer. - **tradeInitTime** (Date) - The time when Steam began processing the item exchange. - **receivedItems** (Array) - An array of `EconItem` objects for items received. - **sentItems** (Array) - An array of `EconItem` objects for items sent. Each object in `receivedItems` and `sentItems` has these properties in addition to standard `EconItem` properties: - **appid** (number) - The AppID of the game to which the item belongs. - **contextid** (string) - The context ID within the app to which this item belonged **before the exchange happened**. - **assetid** (string) - The asset ID of the item **before the exchange happened**. - **amount** (number) - The amount of the stack which was exchanged (usually 1). - **classid** (string) - The classid of the item **before the exchange happened**. - **instanceid** (string) - The instanceid of the item **before the exchange happened**. - **new_assetid** (string) - Only present if the trade completed successfully. The item's new asset ID in its new owner's inventory, **after the exchange**. - **new_contextid** (string) - Only present if the trade completed successfully. The item's new context ID in its new owner's inventory, **after the exchange**. - **rollback_new_assetid** (string) - Only present if the trade was rolled back. The item's new asset ID after it was returned to its original owner's inventory after the trade was rolled back. - **rollback_new_contextid** (string) - Only present if the trade was rolled back. The item's new context ID after it was returned to its original owner's inventory after the trade was rolled back. #### Response Example ```json { "status": "Complete", "tradeInitTime": "2023-10-27T10:00:00.000Z", "receivedItems": [ { "appid": 730, "contextid": "2", "assetid": "1234567890", "amount": 1, "classid": "12345678", "instanceid": "987654321", "new_assetid": "0987654321", "new_contextid": "2" } ], "sentItems": [ { "appid": 730, "contextid": "2", "assetid": "1122334455", "amount": 1, "classid": "87654321", "instanceid": "123456789", "new_assetid": "5544332211", "new_contextid": "2" } ] } ``` ``` -------------------------------- ### Get User Inventory Contents Source: https://context7.com/doctormckay/node-steam-tradeoffer-manager/llms.txt Retrieves the contents of another user's Steam inventory for a specific application and context. This functions similarly to `getInventoryContents` but targets a different user's public inventory. ```APIDOC ## getUserInventoryContents ### Description Retrieves the contents of another user's Steam inventory. Works the same as getInventoryContents but for any Steam user's public inventory. ### Method `getUserInventoryContents` ### Parameters #### Path Parameters - **steamID** (string | SteamID) - Required - The SteamID of the user whose inventory to retrieve. - **appId** (number) - Required - The AppID of the game. - **contextId** (string | number) - Required - The context ID of the inventory. - **tradableOnly** (boolean) - Required - Whether to only return tradable items. - **callback** (function) - Required - A callback function that receives an error object (if any), an array of inventory items, and an array of currency items. ### Request Example ```javascript // Get another user's CS:GO inventory let steamID = "76561198006409530"; manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory, currencies) { if (err) { console.log("Error loading user inventory:", err); return; } console.log("User has " + inventory.length + " tradable CS:GO items"); // Find valuable items let knives = inventory.filter(item => item.type && item.type.includes('Knife')); console.log("Found " + knives.length + " knives"); knives.forEach(function(knife) { console.log("Knife:", knife.name, "- Asset ID:", knife.assetid); }); }); ``` ``` -------------------------------- ### createOffer Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOfferManager Creates a new empty TradeOffer object. Can accept a partner's SteamID or trade URL, and optionally their access token. ```APIDOC ## POST /createOffer ### Description Creates a new empty TradeOffer object. Can accept a partner's SteamID or trade URL, and optionally their access token. ### Method POST ### Endpoint /createOffer ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **partner** (string|object) - Required - A trade URL, a SteamID object, or a string that can parse into a SteamID. - **token** (string) - Optional - Your trade partner's access token, if needed. ### Request Example ```json { "partner": "https://steamcommunity.com/tradeoffer/new/?partner=46143802&token=KYworVTM" } ``` ### Response #### Success Response (200) - **offerId** (string) - The ID of the newly created trade offer. - **status** (string) - The initial status of the trade offer. #### Response Example ```json { "offerId": "1234567890", "status": "Active" } ``` ``` -------------------------------- ### Adding Items to Offer Source: https://github.com/doctormckay/node-steam-tradeoffer-manager/wiki/TradeOffer Methods for adding items to a new trade offer. `addMyItem` adds a single item, while `addMyItems` adds an array of items. ```APIDOC ## addMyItem(item) ### Description Adds a given item to a new trade offer. The item object should be in the same format as is returned by the Steam inventory. ### Method `addMyItem(item)` ### Parameters #### Path Parameters - `item` (object) - Required - An item object with properties: `assetid` (or `id`), `appid`, `contextid`, and optionally `amount`. ### Returns - `true` if the item was successfully added. - `false` if the item was already in the offer. ### Request Example ```javascript var item = { assetid: '1234567890', appid: 440, contextid: 2, amount: 1 }; offer.addMyItem(item); ``` ``` ```APIDOC ## addMyItems(items) ### Description Convenience method which simply calls `addMyItem` for each item in the array. ### Method `addMyItems(items)` ### Parameters #### Path Parameters - `items` (Array) - Required - An array of item objects, each in the format required by `addMyItem`. ### Returns The number of items that were successfully added. ### Request Example ```javascript var items = [ { assetid: '1234567890', appid: 440, contextid: 2 }, { assetid: '0987654321', appid: 570, contextid: 2, amount: 2 } ]; var addedCount = offer.addMyItems(items); console.log('Number of items added:', addedCount); ``` ```