-1

Hello i have a request which fetch some json data from third party API:

request({
    url: 'https://api.steampowered.com/IEconService/GetTradeOffers/v1/?key=MYAPIKEY&get_sent_offers=1&active_only=1&format=json',
json: true
}, (err, responser, body, undefined) => {
tradeItems = JSON.stringify(body.response['trade_offers_sent'][0].items_to_give);
});

How can i send tradeItems fetched data to offer.addTheirItems value?

client.on('webSession', function(sessionID, cookies) {
    manager.setCookies(cookies, function(err) {
        if (err) {
            console.log(err);
            process.exit(1); 
            return;
        }



let offer = manager.createOffer("https://steamcommunity.com/tradeoffer/new/?partner=123456789&token=1234");
            offer.addTheirItems();
            offer.setMessage("");
            offer.send(function(err, status) {
                if (err) {
                    console.log(err);
                    return;
                }

user6215911
  • 21
  • 1
  • 5

1 Answers1

1

First, that's are javascript's async issue.

The solution is in many ways.

  1. change the request function to async function. and make tradeItems variable to outside from request function. I recommend request-promise module

  2. move below codes to in upper code's callback function.

This is a simple answer because your sample code is separated into two parts.