1

I don't know why this would be unauthorized. I checked that the api_key and puuid are correct. When I made a request to another Riot API in a similar way, I got the desired result (status code: 200). I'm guessing there is a typo in the URL that sent the request, but I can't find where it went wrong.

import fetch from 'node-fetch'

const getMatchList = async () => {
  const puuid = 'XXXXXXXX'
  const api_key = 'XXXXXXX'
  const res = await fetch(
    `https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1?api_key=${api_key}`
  )
  const myJson = await res.json()
  console.log(myJson) // { status: { message: 'Unauthorized', status_code: 401 } }
}
  • 2
    `I'm guessing there is a typo in the URL` only you know if you made a typo in a URL that you are using - perhaps the typo is in your credentials - have you tried using [this page](https://developer.riotgames.com/apis#match-v5/GET_getMatchIdsByPUUID) to test? – Bravo Jun 09 '22 at 06:27
  • @Bravo I did it before, it works fine (status code 200). I checked the `api_key` several times and sent a request from my code writen in node.js to another riot api, but it works fine. – user17692924 Jun 09 '22 at 06:50
  • 2
    Yes, there is a typo in the URL. It should be `&api_key=`, not `?api_key=`. This is because the query string starts at the first `?` – Phil Jun 09 '22 at 07:02

1 Answers1

0

Change the '?' in the api_key for '&' just like that: Original: https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1?api_key=${api_key}

Right: https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1&api_key=${api_key}