Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Clash Royale Node Fetch with Key

Im trying to make a discord bot where if you type -cr into the chat, it takes the Arguments of the user (Being the Clash Royale Player's player tag) and would then use the package node-fetch to receive data with my specified endpoint. I am constantly running into the error of { reason: 'accessDenied', message: 'Invalid authorization' }. Im rather new to this stuff, especially API's, but im hoping to access certain data which I can decide later on (Which I know how to do). My code is :

const fetch = require('node-fetch')

module.exports = {
    name: 'clash',
    aliases: ['cr', 'clashroyale'],
    category: 'This',
    utilisation: '{prefix}clash',

    async execute(client, message) {
        var msgArgs = message.content.slice(this.name.length + 1)
        var endpoint = `/players/${msgArgs}`
        var url = `https://api.clashroyale.com/v1`

        var token = `hidingmytoken`

        fetch(url + endpoint, {
            method: 'POST',
            headers: {
                "Authorization": token
            }
        }).then(data => data.json()).then(json => {
            console.log(json)
        })
    },
};

The message parts with msgArgs and discord sides all work but fetching that clash Royale API is a big hurdle for me. The API for Clash Royale can be found here https://developer.clashroyale.com/#/documentation and Im just generally stuck on this whole concept. Im using version 2.6.6 of node-fetch so I can use the require() method which should work if that does matter. In general, how can I pass my token properly to receive that API data?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Since the Clash Royale API uses bearer authentication, you need to specify that it will be a bearer token.

headers: {
  'Authorization': `Bearer ${token}`
}
about 4 years ago · Santiago Trujillo Denunciar

0

I've implemented the following functionality. The code is written in GO but you can copy the logic and translate into your language.

The library have the following functionality:

  • Login
  • Token generation
  • Token list
  • Token delete

https://github.com/alessiosavi/GoClashRoyale/blob/master/api/auth.go

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda