Jump to content
McKay Development

Recommended Posts

Posted

I am trying to retrieve users inventory by fetching their inventory items using this method and trade URL.

I am getting a malformed response when attempting to fetch their inventory using this method and honestly do not know how to diagnose it, I tried a lot of things.
Error logged from inside the offer.getPartnerInventoryContents() method:

Error fetching inventory: Error: Malformed response
at SteamCommunity.<anonymous> (F:\1 SKINWAREHOUSE\skin-warehouse\server\node_modules\steamcommunity\components\users.js:635:15)

async function testFetchInventory(tradeURL) {
  try {
    // Parse trade URL
    const urlParams = new URLSearchParams(tradeURL.split('?')[1]);
    const partner = urlParams.get('partner');
    const token = urlParams.get('token');
 
    if (!isBotReady()) {
      console.log('Bot is not ready. Skipping reconciliation.');
      return;
    }
   
    // Create the trade offer
    const offer = manager.createOffer(tradeURL);
   
    // Use getPartnerInventoryContents as shown in docs
    return new Promise((resolve, reject) => {
      offer.getPartnerInventoryContents(730, 2, (err, inventory) => {
        if (err) {
          console.error('Error fetching inventory:', err);
          reject(err);
          return;
        }
        console.log('Inventory fetched successfully:', inventory);
 
        // Filter and format tradeable items
        const tradeableItems = inventory.filter(item => item.tradable).map(item => ({
          name: item.market_hash_name,
          assetid: item.assetid,
          appid: 730,
          contextid: 2,
          amount: 1,
          tradable: item.tradable
        }));
 
        console.log('Inventory fetched successfully:', {
          totalItems: inventory.length,
          tradeableItems: tradeableItems.length
        });
 
        if (tradeableItems.length > 0) {
          console.log('First tradeable item:', tradeableItems[0]);
        }
 
        resolve(tradeableItems);
      });
    });
 
  } catch (error) {
    console.error('Error in testFetchInventory:', error);
    throw error;
  }
}

 

function setCookiesAsync() {
  if (cookieSetPromise) {
    return cookieSetPromise;
  }
 
  cookieSetPromise = new Promise((resolve, reject) => {
    client.on('webSession', (sessionid, cookies) => {
      manager.setCookies(cookies, (err) => {
        if (err) {
          console.error('Error setting cookies:', err);
          reject(err);
        } else {
          console.log('Cookies set successfully');
          cookiesSet = true;
          resolve();
        }
      });
    });
  });
 
  return cookieSetPromise;
}
Posted

Getting similar issues with a malformed response error using the getUserInventoryContents too.

Test function

async function testFetchInventory(steamid) {
  try {
    console.log('Starting inventory fetch for steamID:', steamid);
 
    return new Promise((resolve, reject) => {
      manager.getUserInventoryContents(
        steamid,  // Steam ID of the user
        730,      // CSGO App ID
        2,        // Context ID
        true,     // Tradeable only
        (err, inventory) => {
          if (err) {
            console.error('Failed to fetch inventory:', err);
            reject(err);
            return;
          }
 
          console.log('Inventory fetch successful!');
          console.log(`Total tradeable items found: ${inventory.length}`);
         
          // Log first 3 items as a sample
          if (inventory.length > 0) {
            console.log('Sample of first 3 items:');
            inventory.slice(0, 3).forEach((item, index) => {
              console.log(`Item ${index + 1}:`, {
                name: item.market_hash_name,
                assetid: item.assetid,
                tradable: item.tradable
              });
            });
          }
 
          resolve(inventory);
        }
      );
    });
 
  } catch (error) {
    console.error('Error in testFetchInventory:', error);
    throw error;
  }
}

Error

Failed to fetch inventory: Error: Malformed response
    at SteamCommunity.<anonymous> (F:\1 SKINWAREHOUSE\skin-warehouse\server\node_modules\steamcommunity\components\users.js:635:15)
    at Request._callback (F:\1 SKINWAREHOUSE\skin-warehouse\server\node_modules\steamcommunity\components\http.js:67:15)
    at self.callback (F:\1 SKINWAREHOUSE\skin-warehouse\server\node_modules\request\request.js:185:22)
    at Request.emit (node:events:518:28)
    at Request.<anonymous> (F:\1 SKINWAREHOUSE\skin-warehouse\server\node_modules\request\request.js:1154:10)
    at Request.emit (node:events:518:28)
    at Gunzip.<anonymous> (F:\1 SKINWAREHOUSE\skin-warehouse\server\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (node:events:632:28)
    at Gunzip.emit (node:events:518:28)
    at endReadableNT (node:internal/streams/readable:1698:12)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...