Search code examples
javascriptnode.jsdiscord.jsfetch

js - filters in fetch


I have a problem. I'm trying to fetch an API, but theres an error-message which says:
At least one filtering parameter must exist

I found something on google, but nothing of it worked. My code looks like this:

let api = await fetch("https://api.clashofclans.com/v1/clans/#2Q8GRY8LQ", {
  method: `GET`,
  headers: new Headers({
    'Authorization': `Bearer ${API_TOKEN}`,
  })
})
let apiJSON = await api.json()
console.log(apiJSON)

Thanks


Solution

  • Try to encodeURIComponent of the clan tag like this:

    let api = await fetch(`https://api.clashofclans.com/v1/clans/${encodeURIComponent("#2Q8GRY8LQ")}`, {
        method: `GET`,
        headers: new Headers({
           'Authorization': `Bearer ${API_TOKEN}`,
        })
    })
    let apiJSON = await api.json()
    console.log(apiJSON)