Jump to content
McKay Development

Recommended Posts

Posted (edited)

I get this: Error retrieving inventory: Error: HTTP error 401 after a couple of days of running my script. It works for a while then it crashes with that error code. Below is the complete code:

Edit: To clarify, it gets the inventory no problem then just stops working.

 

const express = require('express');
const SteamCommunity = require('steamcommunity'); // Assuming you're using steamcommunity package
const app = express();
const community = new SteamCommunity();
const axios = require('axios'); // Import axios for making HTTP requests

// Define appIDs for different games
const APP_IDS = {
    csgo: 730, // CS:GO
    rust: 252490 // Rust
};

// Route to fetch inventory
app.get('/inventory/:steamID/:game', async (req, res) => {
    const steamID = req.params.steamID;
    const game = req.params.game.toLowerCase(); // Get the game from the URL parameter
    const appID = APP_IDS[game]; // Get app ID from the predefined APP_IDS object
    const contextID = game === 'csgo' ? 2 : 2; // Context ID for CS:GO is 2, Rust is 6

    if (!appID) {
        return res.status(400).json({ error: "Invalid game specified. Please use 'csgo' or 'rust'." });
    }

    try {
        // Get the inventory for the requested steamID and appID
        const inventory = await new Promise((resolve, reject) => {
            community.getUserInventoryContents(steamID, appID, contextID, true, (err, inventory) => {
                if (err) {
                    return reject(err); // Reject the promise with the error
                }
                resolve(inventory); // Resolve the promise with the inventory
            });
        });

        // Return the inventory as a JSON response
        res.json({ steamID, appID, inventory });
    } catch (err) {
        console.error('Error retrieving inventory:', err);
        res.status(500).json({ error: "Error retrieving inventory", details: err.message });
    }
});

// Route to fetch sales history from Skinport
app.get('/sales-history/:appID/:currency', async (req, res) => {
    const { appID, currency } = req.params;

    try {
        // Make a request to the Skinport API to get sales history
        const response = await axios.get('https://api.skinport.com/v1/sales/history', {
            params: {
                app_id: appID,
                currency: currency
            }
        });

        // Return the sales history data from Skinport as JSON
        res.json(response.data);
    } catch (err) {
        console.error('Error retrieving sales history:', err);
        res.status(500).json({ error: "Error retrieving sales history", details: err.message });
    }
});


// Start the Express server
const PORT = 2001; // Set the port
app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});



 

Edited by dawe
Posted
3 hours ago, Dr. McKay said:

Your Steam session expires after a while and you'll need to login again when you get 401.

Thank you. How do I refresh the session as I'm not using an account?

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...