1

js server running some basic api calls from riot.developer. I'm planning on having the match history and stats for each summoner/game available. For this I assume I need the match id's.

I've got a couple of the calls working but seem to have hit a block with this one. Probably staring at my screen for too long! Here is my code for the specific request, for clarity, this request is only for the match id's:

function(data, callback) {
    var URL = 'https://euw.api.pvp.net/api/lol/euw/v2.2/matchlist/by-summoner/' + data.id + 'seasons=SEASON2016&beginIndex=0&endIndex=40&api_key=' + api_key;
    request(URL, function (err, response, body) {
        if (response.statusCode == 200) {
            var json = json.parse(body);
            var matchId = 0;
            for (var c = 0; c < json['matches'].length; c++) {
                data.matches = json['matches'].matchId;
                data.matches = matchId;
                console.log(data.matches);
                callback(null, data);
            }
        } else {
            console.log('line 82');
        }

    });
},

I think the problem I'm having is with the way I'm expressing data.matches. Or that there isn't a timeline?

data.id and api_key are defined outside of this function and are working correctly. Anyway, thanks for any help you guys might be able to provide.

I should probably mention i have express-handlebars installed.

user7630391
  • 33
  • 1
  • 6

1 Answers1

0

Ok I think I've worked out the problem. (It took me too long!) Here is my edited function:

    function(data, callback) {
    var URL = 'https://euw.api.pvp.net/api/lol/euw/v2.2/matchlist/by-summoner/' + data.id + '?seasons=SEASON2016&beginIndex=0&endIndex=40&api_key=' + api_key;
    request(URL, function(err, response, body) {
      if(response.statusCode == 200) {
        var json =JSON.parse(body);
        for(var c = 0; c < json ['matches'].length; c++) {
        data.matches = json['matches'][c].matchId;
        console.log(data.matches)
      };
        callback(null, data);
      } else {
        console.log('line 78');
    }
    })
    }

This has output 40 matchId's in my terminal. Just need to figure out how to add an index now ;D

user7630391
  • 33
  • 1
  • 6
  • 1
    If you are using plain Javascript with Riot API, your key is open for everyone. Call it from a server instead. If you prefer to use node.js there is already libraries for it so you don't have to worry about these things: To install it type in cmd: npm install irelia, then download this main.js: https://github.com/Talha-T/irelia/blob/master/lib/main.js and replace it with Irelia's main.js. Also this readme should make you going: https://github.com/Talha-T/irelia/blob/master/README.md – Talha Talip Açıkgöz May 12 '17 at 10:54