Jump to content
McKay Development

How do I sell an item via httpRequestPost?


What Comes Around

Recommended Posts

Good day/night, I'd like to ask what I am doing wrong? Here is what I have:

client.logOn(loginOptions);
client.on('loggedOn', () => {
    console.log('logged on');
    client.setPersona(1);
});

client.on('webSession', async (sid, cookies) => {
    manager.setCookies(cookies);
    community.setCookies(cookies);
    community.startConfirmationChecker(20000, config.identity_secret);
    let item = await getItem()
    var requestoptions = {
        form: {
            sessionid: community.getSessionID(),
            appid: item.appid,
            contextid: item.contextid,
            amount: 1,
            price: 10
        },
        headers: {
            'Origin': 'http://steamcommunity.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Referer': 'http://steamcommunity.com/my/inventory/',
            'Connection': 'keep-alive',
            'Cookie': cookies,
            'Host': 'steamcommunity.com',
			'Accept-Encoding': 'gzip, deflate',
			'Accept-Language': 'en-US,en;q=0.5'
        },
        json: true
    }
    console.log(requestoptions)
    community.httpRequestPost('https://steamcommunity.com/market/sellitem/', {requestoptions}, (err, response, json) => {
        if (err) {
            console.log(err.toString());
            return;
        }
        console.log(json)
    }, "steamcommunity")
})

const getItem = () => {
    return new Promise((resolve, reject) => {
        manager.getInventoryContents(730, 2, true, (err, inventory) => {
            if (err) {
                reject(err);
            } else {
                resolve(inventory[0]);
            }
        })
    })
}

I keep getting: Error: HTTP error 400

Any advice?

Edited by What Comes Around
Link to comment
Share on other sites

15 hours ago, Dr. McKay said:

Get rid of the curly braces around requestoptions. And also quit using the confirmation checker as it's been deprecated for years.

Oops, my bad. It was old code that I copy pasted. I stopped using confirmation checker :) Also, still getting 400, what could I be doing wrong? Could it be the user agent? I've also tried sending the request to the http address instead, but I got either Malformed Request (without curly braces around requestoptions) or a redirect (with curly braces around requestoptions).

Link to comment
Share on other sites

19 hours ago, What Comes Around said:

Oops, my bad. It was old code that I copy pasted. I stopped using confirmation checker :) Also, still getting 400, what could I be doing wrong? Could it be the user agent? I've also tried sending the request to the http address instead, but I got either Malformed Request (without curly braces around requestoptions) or a redirect (with curly braces around requestoptions).

Sorry, the redirect was the result of me trying http not https, however steam redirects http requests to https. Had nothing to do with curly braces. Also I read from a similar thread : https://dev.doctormckay.com/topic/1495-automatically-selling-steam-items-error-400/?tab=comments#elControls_4826:~:text=When you're doing things on the,any of those other headers either. that the headers shouldn't be entered manually. Is there a way for me to extract that data from the client by any chance?

 

Link to comment
Share on other sites

On 12/27/2020 at 9:50 PM, Dr. McKay said:

You need to specify Origin and Referer manually, but all the other headers you're specifying should be left out as they're HTTP protocol-level headers that request will set on its own.

Thanks! Here is what I have right now:

const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const config = require('./config');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');

const client = new SteamUser();
const community = new SteamCommunity();
const manager = new TradeOfferManager({
    steam: client,
    community: community,
    language: 'en'
})

const loginOptions = {
    accountName: config.username,
    password: config.password,
    twoFactorCode: SteamTotp.generateAuthCode(config.shared_secret) 
}

client.logOn(loginOptions);
client.on('loggedOn', () => {
    console.log('logged on');
    client.setPersona(1);
});

client.on('webSession', async (sid, cookies) => {
    manager.setCookies(cookies);
    community.setCookies(cookies);
    let item = await getItem()
    var requestoptions = {
        form: {
            sessionid: community.getSessionID(),
            appid: item.appid,
            assetid: item.assetid,
            contextid: item.contextid,
            amount: 1,
            price: 10
        },
        headers: {
            'Origin': 'https://steamcommunity.com',
            'Referer': 'https://steamcommunity.com/my/inventory/',
            'Cookie': cookies,
            'Host': 'steamcommunity.com',
        },
        json: true
    }
    console.log(requestoptions)
    community.httpRequestPost('https://steamcommunity.com/market/sellitem/', requestoptions, (err, response, json) => {
        if (err) {
            console.log(err.toString());
            return;
        }
        // console.log(json)
        console.log(response)
    }, "steamcommunity")
})

const getItem = () => {
    return new Promise((resolve, reject) => {
        manager.getInventoryContents(730, 2, true, (err, inventory) => {
            if (err) {
                reject(err);
            } else {
                resolve(inventory[0]);
            }
        })
    })
}

I've added the assetid because I found that steam uses that on their website for market sell requests. The headers that are set by HTTP protocol have been removed. I am still getting the 400 error. I am thinking I should maybe use the steam client in a sandbox and api call log to find out exactly what I am missing. Or at least I would be able to slowly remove unnecessary fields until I have something basic I can use without getting 400 statuses. So far I have gotten sell orders working on chrome using puppeteer and just using cors mode, but getting inventory information and other account details with puppeteer would be a real hassle when as great of a library as yours exists. So this is where I am, I will try to get api logging working and hopefully find out what I am missing. Or of course if you see any mistakes please let me know.

Link to comment
Share on other sites

On 12/31/2020 at 9:57 AM, Dr. McKay said:

Only set Origin and Referer. Do not set Host or Cookie.

OOPS, that makes sense, because I have already set cookies for community. It is now working. Thank you very much! I would also like to ask if using this extensively could be a ban-able offence on steam? And thanks again for your help, really appreciate it! I also really appreciate all of your work in general!

Link to comment
Share on other sites

  • What Comes Around changed the title to How do I sell an item via httpRequestPost?

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