How to use clash-of-clans-api in NodeJs

Ion Utale
4 min readJun 20, 2020


guide for complete beginner, new to programming




we will first create a very fast server-application, and later in part 2 we will go into details about how use the information.

Lets start

  1. Go to: and download the LTS version.
  2. Install Nodejs on your machine. ( in this case, just press next as fast as you can )
  3. Go to: and download and then install the “code editor”.
  4. Go to “Desktop”, create a new folder named “clash-of-clan-server-application”. ( please youse the same exact name )
  5. Open VS Code, and drag & drop the folder “clash-of-clan-server-application” into VS Code.
  6. Go do: Navbar of VS Code and open a new terminal

7. Into the terminal write: npm init and then press enter until it finis asking questions.

8. Still in terminal write the command: “npm i clash-of-clans-api” and press enter

9. Create a new file called “coc.js

10. Ok, now is time to create the clash of clan api token. To do that we need to go to the and create a new account.

11. Go to “my account

12. Click on “create new key”

13. Enter the values exactly like me, and click on “Create Key

for security reasons i offuscate my ip

For the ip, go on google and write “show my ip” and paste the ip into the allowed ip. ( this is important, suppercell won’t give you information if the ip does not match )

14. Open the newly created key

15. And Copy the “token

16. Go to VS Code coc.js, write const COC_API_TOKEN = “”, then paste the “token” between the quotes. ( check the beginning and the end of the quotes, so they don’t contain any spaces this is very important )

17. Paste this code after the token :

The file coc.js should look like this:

18. Go to terminal and write the command “node coc.js” and press enter

you are now getting the information about the player in this precise moment.

There is no way to look at the history of the player, but we can create an app that will save the information about the player every one hour and save it into a db. this way we can track a specific player “progress, donations, activity” and much more.


the “playerByTag” is not present into the documentation in Github so i thought this will create confusion for junior developers

lets add also the “clanByTag” info

19. Add this call to the file:

final code should look like this

the module also covers this API calls

This is all for part 1. Give it a round of applause if you like it, and use the comments bellow or Github issues to post any trouble that you have with this example.

Thank you for reading this.

(Update November 2021)

I’m back on writing clash of clan tutorials, here is how you can create your own proxy on Google Cloud Platform with a static IP let me know what you think and if you need anything else. Feel free to ask me anything, consider me you friend.