Clash Royale is a freemium strategy game by Supercell. In this tutorial, I’ll show you how to get a Clash Royale API token and how to make requests to the Clash Royale API in Google Sheets:
Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.
1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install
2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.
In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
To get your Key and Token, first log in to your Clash Royale developer account, or sign up for one if you haven’t already.
After logging in to your developer account, click on your username and then click My Account:
The My Keys section will then be displayed.
Click the Create New Key button:
Next, complete the key name and description.
Add an allowed IP address by completing the corresponding field and clicking the +Add IP Address button.
Finally, click the Create Key button:
Your Clash Royale API key will then be created.
Then, click the arrow next to your key to display your token:
Your Clash Royal API token will then be displayed.
Copy and paste your token to a safe location, because you’ll need it in the next steps:
In this section, I’ll show you how to browse the Clash Royale API documentation to find an API endpoint that retrieves the specific information you need from your Clash Royale account.
If you already know your API URL endpoint, or you want to use the same example URL as us, just skip to Step 4.
First, open the Clash RoyaleAPI documentation page: https://developer.clashroyale.com/#/documentation
The main page contains a list of endpoint’s categories: clans, players, cards, tournaments, locations and global tournaments:
Clicking on the corresponding Show/Hide link for a category will expand a list of specific endpoints.
Clicking one of the available Clah Royale API’s endpoints will open its documentation page, containing the endpoint’s HTTP method and URL, a short description of its purpose, a list of the accepted parameters and response messages, as well as a sample request and its associated sample response.
The example endpoint we’ll take a look at is /players/{playerTag}/battlelog from the Players category. The corresponding URL for this endpoint is:
https://api.clashroyale.com/v1/players/playerTag/battlelog
All API calls to Clash Royale should be made with this base URL:
https://api.clashroyale.com/v1/
The Cards endpoint, which gets list of available cards.
Method: GET API URL Path: https://api.clashroyale.com/v1/cards Headers: Header 1 Key: Accept Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
your_token is the value of the token you obtained previously, in Step 2. There should be a literal space between Bearer and your_token.
The GET /locations/global/seasons endpoint, which lists top player league seasons.
Method: GET API URL Path: https://api.clashroyale.com/v1/locations/global/seasons Headers: Header 1 Key: Accept Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
your_token is the value of the token you obtained previously, in Step 2. There should be a literal space between Bearer and your_token.
The GET /challenges endpoint, which gets current and upcoming challenges. Challenges are returned as chains.
Method: GET API URL Path: https://api.clashroyale.com/v1/challenges Headers: Header 1 Key: Accept Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
your_token is the value of the token you obtained previously, in Step 2. There should be a literal space between Bearer and your_token.
The GET /locations endpoint, which lists locations.
Method: GET API URL Path: https://api.clashroyale.com/v1/locations Headers: Header 1 Key: Accept Header 1 Value: application/json Header 2 Key: Authorization Header 2 Value: Bearer your_token
your_token is the value of the token you obtained previously, in Step 2. There should be a literal space between Bearer and your_token.
Pagination is a process that is used to divide a large dataset into smaller chunks (pages). Usually the endpoints that return a list of resources support pagination.
Most of the Clash Royale API endpoints use the pagination option. This means you need to add pagination some of these parameters at the end of the URL:
limit
– limit the number of items returned in the response.;after
– return only items that occur after this marker. Before marker can be found from the response, inside the ‘paging’ property. Note that only after or before can be specified for a request, not both;before
– return only items that occur before this marker. Before marker can be found from the response, inside the ‘paging’ property. Note that only after or before can be specified for a request, not both.Each endpoint that needs pagination will have in its documentation relevant information on which of these parameters you can use and how to do it.
Example: https://api.clashroyale.com/v1/cards?limit=200
In the example above, the data set will have a limit of 200 records.
Okay, now we’re in the home stretch. Now go back to your Google Sheet and make sure that the Apipheny add-on is open on the Import tab. With the Import Tab open, enter these details into the add-on:
Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) as required by your Clash Royale API endpoint. For this example, we are using the GET method.
API URL: In Step 3, I explained how you can find the Clash Royale API endpoint that you need. Now copy the complete API URL into the Apipheny add-on, where it says API URL Path, followed by any GET parameters required for your query.
For this example, we are using the Clans endpoint, which retrieves all the information about a clan. The corresponding URL for this endpoint is:
https://api.clashroyale.com/v1/clans
If you’re following the same example as us, just copy and paste the URL above into the “API URL” field in Apipheny.
Headers: In the Headers section of the Apipheny add-on, add two rows, with the following keys and values:
Header 1 Key: Accept Value: application/json
Header 2 Key: Authorization Value: Bearer your_token
your_token is the value of the token you obtained previously, in Step 2. There should be a literal space between Bearer and your_token
This is what your API request should look like when entered into Apipheny:
The last step is to click the Run button at the bottom of the Apipheny add-on and then your Clash Royale data will be imported into your Google Sheet:
After making a successful request to the Clash Royale API, try querying a different Clash Royale API endpoint, or try using one of the more advanced features in the Apipheny add-on, such as:
Crypto API Tutorials: