Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!