410 for retrieving player details via axios (JavaScript)


#1

Hey,

trying to fetch data from the /players endpoint, but getting a 401 authorization error every time.

example URL: https://open.faceit.com/data/v4/players?nickname=SHEIX&game=csgo

I get the right result when I access the URL via Postman, but I always get 401 when doing the same thing with axios.

Any ideas of what I’m missing here?

async fetchAccountIdFromAPI() {
      let config = {
        headers: {
          accept: "application/json",
          Authorization: "Bearer my-api-key"
        }
      };

      let params = {
        params: {
          nickname: "SHEIX",
          game: "csgo"
        }
      };

      try {
        const response = await axios.get(this.url, params, config);
        console.log(response);
      } catch (error) {
        console.error(error);
      }
    },

#2

I fixed this by putting the params inside the config:

let config = {
        headers: {
          accept: "application/json",
          Authorization: "Bearer " + this.key
        },
        params: {
          nickname: this.searchInput,
          game: "csgo"
        }
      };

#3

Hi SHEIX,
yeah, the second try is right and it should works as expected.
As far as I know, the axios get method expects a config as second parameter and you were passing an object with only one key (params), so the Authorization header were missing.
That’s why you get 401, which is an authentication error.

Cheers!
Lorenzo


#4