Jump to content
McKay Development

TypeError: Cannot read property 'appid' of undefined


yoba

Recommended Posts

 Please help with my problem. I do not know why the 'appid' is not defined

 

Stack trace:

Logged into Steam
/Users/user/Documents/node/steam/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:419
	if (typeof details.appid === 'undefined' || typeof details.contextid === 'undefined' || (typeof details.assetid === 'undefined' && typeof details.id === 'undefined')) {
	                  ^

TypeError: Cannot read property 'appid' of undefined
    at addItem (/Users/user/Documents/node/steam/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:419:20)
    at TradeOffer.addTheirItem (/Users/user/Documents/node/steam/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:374:9)
    at manager.loadUserInventory (/Users/user/Documents/node/steam/project4.js:80:12)
    at SteamCommunity.<anonymous> (/Users/user/Documents/node/steam/node_modules/steamcommunity/components/users.js:331:5)
    at Request._callback (/Users/user/Documents/node/steam/node_modules/steamcommunity/components/http.js:67:15)
    at Request.self.callback (/Users/user/Documents/node/steam/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/Users/user/Documents/node/steam/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)

Code:

function sendRandomItem() {

	const partner = 'partner_code';
	const appid = 730;
	const contextid = 2;
	const offer = manager.createOffer(partner);

	manager.loadInventory(appid, contextid, true, (err, myInv) => {

		if (err) {
			console.log(err);
		} else {
			const myItem = myInv[Math.floor(Math.random() * myInv.length - 1)];
			offer.addMyItem(myItem);

			manager.loadUserInventory(partner, appid, contextid, true, (err, theirInv) => {
				if (err) {
					console.log(err);
				} else {
					const theirItem = theirInv[Math.floor(Math.random() * theirInv.length - 1)];
					offer.addTheirItem(theirItem);

					offer.setMessage(`Will you trade your ${theirItem.name} for my ${myItem.name}?`);
					offer.send((err, status) => {
						if (err) {
							console.log(err);
						} else {
							console.log(`Sent offer. Status: ${status}.`);
						}
					});
				}
			});
		}
	});
}

Link to comment
Share on other sites

Logged into Steam

{ Error: There was an error sending your trade offer.  Please try again later. (15)

    at Object.exports.makeAnError (/Users/code/Documents/node/steam/node_modules/steam-tradeoffer-manager/lib/helpers.js:12:12)

    at SteamCommunity.manager._community.httpRequestPost (/Users/code/Documents/node/steam/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:513:12)

 

I do not understand why I get this error. What am I doing wrong? I already read about this error. But there are no restrictions on my accounts, what could be the problem?

Link to comment
Share on other sites

  • 5 months later...
  • 4 weeks later...

When you add items to the offer (with .addMyItem and .addTheirItem) you need to specify appid and contextid of items.

So, instead of

offer.addMyItem(myItem);

Replace with:

offer.addMyItem({
    'assetid': myItem.assetid,
    'appid': appid,
    'contextid': contextid
});

Same for

offer.addTheirItem(theirItem);

Replace with:

offer.addTheirItem({
    'assetid': theirItem.assetid,
    'appid': appid,
    'contextid': contextid
});
Link to comment
Share on other sites

  • 5 months later...
  • 3 weeks later...

you guys have answer for this? cant get it right

 

 offer.addMyItem({
        'assetid': myItem.assetid,
        'appid': appid,
        'contextid': contextid
    });

      manager.loadUserInventory(
        partner,
        appid,
        contextid,
        true,
        (err, theirInv) => {
          if (err) {
            console.log(err);
          } else {
            const theirItem =
              theirInv[Math.floor(Math.random() * theirInv.length - 1)];
            offer.addTheirItem({
              'assetid': theirItem.assetid,
              'appid': appid,
              'contextid': contextid
          });
Link to comment
Share on other sites

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