Getting Game Data Using the Riot API in Your Web Browser

Introduction to using the Riot API in Python Part 2

TheConnoisseur
7 min readSep 7, 2023

This is part 2 of a tutorial series where I walkthrough creating a mini project using the Riot API in Python.

Here is a link to the first part of the series if you want to go from the beginning: Using The Riot API with Python. Part 1, Defining our mini project and… | by TheConnoisseur | Sep, 2023 | Medium

Empreyan Jax from League of Legends

Welcome to the 2nd part of this small tutorial series on using the Riot API in Python.

Previously I introduced the mini project we’d be working on and showed you how to acquire your own development API key.

In this part, we’ll take a look at some of the APIs Riot offers to us, which ones we’ll be using in our Python script and how you can call them in your web browser.

Looking through the APIs on offer

To see all the APIs offered by Riot, simply click the button in your toolbar at the top labelled “APIs”.

Note this is the same page you generated your development API key from.

Riot Developer Portal, generate development API screen

Now you will see a menu which looks like this:

Riot developer portal, apis screen

On the left is a vertical toolbar which you can use to navigate all the different APIs you can use, and on the right are the different API end points you can use to make calls to the API.

I recommend looking through each of these and seeing what you can find. You’ll find API endpoints for all kinds of data from League of Legends, Valorant, Legends of Runeterra and more.

Which APIs Will We Be Using?

As a reminder, we are creating a script which will take in a player’s League of Legends in-game name and return their win ratio from the last 20 games played.

We will be using 3 API end points in our mini project:

  1. SUMMONER-V4, get summoner profile by summoner name, (Riot Developer Portal (riotgames.com)) accepts a player’s in-game name (their summoner name) and returns their profile data.
  2. MATCH-V5, get match id’s by player puuid, (Riot Developer Portal (riotgames.com)) accepts a players puuid and returns match ids from the last 20 games they’ve played.
  3. MATCH-V5, get match information by match id, (Riot Developer Portal (riotgames.com)) takes a match id and returns information about that match.

Note, League of Legends calls players ‘summoners’ and in this tutorial I will use them interchangeably.

Now that you know what information we can gather from the API, let’s detail the exact steps our script will make:

  1. Getting a given player’s puuid by their player name.
  2. Using their puuid to get the ids of the last 20 matches they have played.
  3. Get the match information associated with each match id and tally up the wins and losses
  4. Calculate and return their win percentage

Our mini project can be fully decomposed into 4 simple steps, only using 3 API endpoints. We’ll start implementing these steps in Python code in the next part of the tutorial.

But first, let’s talk about how you can make an API call in your browser…

Making API Calls in Your Web Browser

Before we get into making API calls in Python, let’s talk about how you would call them in your web browser first.

You make API calls using HTTP Get requests, and then the data gets returned to you in JSON format.

As such, you can simply type a valid URL into your browser to make a call to the API.

You can use the Riot Developer Portal API interface to generate these URLs for you. Additionally, it can also make the API calls and present the returned data for you as well.

If this sounds a bit confusing then don’t worry, taking a look at an example will clear up any confusion you may have.

Lets walk through an example of how this works

Let’s make a call to the SUMMONER-V4 API endpoint, where we pass a summoner name and get their profile details returned, including their puuid.

Navigate to the SUMMONER-V4 API endpoint in your toolbar, or follow this link to it: Riot Developer Portal (riotgames.com).

You will see a drop down like this:

Riot Developer Portal, SUMMONER-V4 API endpoint

This shows details of the information returned from a successful API call.

The player’s account id, profile icon id, revision date, name, id, puuid and summoner level returned to us in JSON format.

Just below that we can see the response errors that can go wrong with a call to the API:

Riot API call response errors

You don’t need to worry about these much for now. They will become more relevant when checking for them when writing our Python script.

The most common of these you will see is an 401 forbidden access error. Most of the time this will be caused by forgetting to attach a valid API key to your request.

Just below that, you will see the page where you make calls to the API in the developer portal:

Riot API call, execute API call menu with given parameters

Let’s make a call to the API where I want to get the profile details of my summoner with the in-game name “Conoisseur”.

We will need to select the region this summoner is in, EUW in this case, and select to include the API key in the header param to authorise access to the API.

Make sure your development API key is still valid

Now let’s execute our requests by pressing the big red button labelled “execute request”. The outcome of the request will appear in the window for you.

The first thing you want to do is check the response code:

Response code 200

You want it it to be 200, which says the request was successful. If it’s in the 400 to 500 range, check the screenshot above about response codes to get an idea why your request wasn’t successful.

If your request was successful then the information returned by the API call will be in the response body:

Response body from successful API call

This contains the information you requested in the API call. As you can see it contains information about the account. We will be using this information our Python script in the next part of tutorial

The last important part in our response is the request URL:

This is the URL we can copy into our web browser to make the API call from there, and this how we will be making calls to the API in Python.

So let’s try it. Copy the request URL generated for you, paste it into your browser and press enter.

You will get a JSON response which looks like this:

JSON response from invalid call to API

Not a success, but can you work out why?

Well, whenever you encounter an error like this, double check your API key is valid and attached to your request.

In this case it’s not attached, so we need to add our development API key to the end of our URL like this: “https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-name/Conoisseur?api_key=YOUR_API_KEY” where you replace “YOUR_API_KEY” with your developement API key.

Now when you execute the request, you will get something which looks like this:

JSON response in web browser from successful call to API

Success!

That wraps it up for this part of the tutorial.

We looked at the different API calls we will be using and learnt how to make them.

In the next part, we’ll take a look at how to code this all out in Python and give Python access to that JSON response we just generated from the API.

Next Part: Querying The Riot API with Python: A Simple Introduction | by TheConnoisseur | Sep, 2023 | Medium

Previous Part: Using The Riot API with Python. Part 1, Defining our mini project and… | by TheConnoisseur | Sep, 2023 | Medium

Thanks for reading!
If you enjoyed this article then feel free to clap it and check out some of my other articles :)

--

--

TheConnoisseur

Avid Computer Enjoyer, I write about topics I'm interested in, mainly programming.