Skip to content
Advertisement

How can I fetch Clash Of Clans API?

I’m trying to do a discord bot with the clash of clans api. But I get a weird error message. Thanks

Error Message:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>v1/clans/LYVVC9JQQ</Key><RequestId>67H6BCRSJ41W6K6X</RequestId><HostId>mPhpqkXy1qKENdOnt+CPhfQn4rK0hGhaMxaLq9q21Ehtbs/CMzSgqHy9TA6L7hii0PY9+Lo2rzg=</HostId></Error>

async function getClashofClansAPi() {
    let clashofClansAPI = await fetch(`https://developer.clashofclans.com/v1/clans/LYVVC9JQQ`)
    let cocApi = await clashofClansAPI.text()
    console.log(cocApi)
}
getClashofClansAPi()

Advertisement

Answer

The API URL is api.clashofclans.com and you are also lacking an API KEY in your authorization header unless you removed it for security purposes

Clash of Clans API uses JSON Web Tokens for authorizing the requests. Tokens are created by developers on My Account page and must be passed in every API request in Authorization HTTP header using Bearer authentication scheme. Correct Authorization header looks like this: “Authorization: Bearer API_TOKEN”.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement