Skip to main content

Clash of Clans API Tutorial – Clan Details

Today we will learn how to accept CLAN NAME as input from user and show CLAN Details on a webpage. Before we proceed you should know How to generate access key for Clash of Clans API and How to fetch and display API data on a web page. If you have not read previous posts I will strongly recommend you to take 5 mins and go through those posts. Alright lets build a new page which will accept Clan Name from user and will display relevant information.

How to show a clan search form in a webpage

Step 1: Build a new page with the same template as we have used for Leagues API demo (can be found at last of this post). Just Copy that page and do some modifications in the code. First thing we need a Search Form in which a user can mention CLAN Name and other details. To keep it simple we will just search for clan name and list down all the clans with that name. Create a page in WordPress and give it any name say “ClanSearch”. Now in your template page add below code:
Clan Search:<input type=”text” id=”clanname” name=”clanname” placeholder=”Enter clan name” />
<input type=”submit” value=”Search”>

Step 2: Once you have created a form to read clan name enter below code to check if user submitted any clan name. If not we will use a default clan name (RETURNOFTHEFALL is my clan).
if(isset($_POST[‘clanname’]) && (!(empty($_POST[‘clanname’]))) ) { /*start – if clan name is entered */
$var_clanname= strtoupper($_POST[‘clanname’]) ;

Step 3: Fetch API Data for the clan name submitted by user.
$api_key = ‘YOUR_API_KEY_HERE’;
$url = ‘’.$var_clanname;
$var_cntr = 0;
$var_cntr1 = 1;
$headers = array(
“Accept: application/json”,
“Authorization: Bearer ” . $api_key
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL,$url);

$result = curl_exec($ch);
$response = json_decode($result,true);

Step 4: Show data on a webpage now.
echo “<center><table>”;
echo “<tr><th>S.No</th><th>Badge</th><th>Clan Tag</th><th>Clan Name</th><th>Location</th><th>Clan Level</th><th>War Wins</th></tr>”;
while (!empty($response[‘items’][$var_cntr][‘tag’]))
echo “<tr>”;
echo “<td>”.$var_cntr1.”</td><td><img src=”.$response[‘items’][$var_cntr][‘badgeUrls’][‘small’].” /></td><td>”.$response[‘items’][$var_cntr][‘tag’].”</td><td>”.$response[‘items’][$var_cntr][‘name’].”</td>
echo “</tr>”;
echo “</table></center>”;

League API Details

S.NoLeague IDLeague NameLeague Badge
229000001Bronze League III
329000002Bronze League II
429000003Bronze League I
529000004Silver League III
629000005Silver League II
729000006Silver League I
829000007Gold League III
929000008Gold League II
1029000009Gold League I
1129000010Crystal League III
1229000011Crystal League II
1329000012Crystal League I
1429000013Master League III
1529000014Master League II
1629000015Master League I
1729000016Champion League III
1829000017Champion League II
1929000018Champion League I
2029000019Titan League III
2129000020Titan League II
2229000021Titan League I
2329000022Legend League

Popular posts from this blog

Clash of Clans API – Basics Part 1 | API Tutorial

I am sure you love Clash of Clans because you are reading this post and wish to know more about COC API. Few years back Supercell launched Clash of Clans API for public use. Clash of Clans API gives so much information about Clans and Clan Wars however in the next version we can expect individual clasher details too. After which Clash of Clans API will become truly helpful in getting insight into Clan data.
Clash of Clans API tutorial part 1 Target Audience Non-technical Clash of Clans clashers who want to use API to get insight into their Clan using available historical data.
Technology Used in APIWordPress as platform
PHP as programming language
MySQL as Database What is Clash of Clans API? COC API can be considered as a medium to access clash of clans data in secure manner.
What all information is available in Clash of Clans API? In VERSION v1, following information is available:

Clans: Search for Clans using Clan Tag, Name, Clan Level, Clan Points, Clan Members etc. You can also sea…

Drag attack strategy for th8 ultimate guide

Clash of clans community discovered thousands of interesting and effective attack strategies including drag attack strategy. Drag attack normally starts at th7 and lasts till th9(I saw to use them even in th10).
The combination of each townhall would be different. Here we are experimenting with a th8 base. It's not to say it's as popular as effective in th8.
Troops for a successful drag attack
Dragons-10/9(Player differ)Balloon-0/4 Max or lvl 6 loons in castleLightning spell-2Rage spell-1Eq spell-1Poison/haste-1 in castle
If you are taking 9 drags. Make sure to take 4 loons. How many drags you have to choose depend on the base you're going to attack.First Step:
You don't have to clear clan castle troops in drag attack. However be careful to drop the poison. Anyhow drop 2 lightning spell and 1 eq spell on any air defence and it will destroy the air defence.
Second Step:
Now release all drags on a line from the closest side of air defence. Once they are ready to taking da…

Th9 witch bowler combo attack strategy

This attack strategy is basically useful in the bases with centralised air defences. If the air defence is in outside compartments then the strategy might not as effective with is attacking strategy.
Begain with witch with bowler Here the strategy goes in such way : Golem, Bowlers and Heroes along with wizards are the kill squad. These troops will break major defences like x-bows and air defence with few other structures and make the base easy for the the witches who are healed continuously by the healer. Minimum troops & spells levels requirements to get success in this th9 attack strategyWitch lev 2Jump spell lev 2Golem lev 3Poison spell lev 2Wizard lev 6Healing spell lev 5Rage spell lev 5Archer lev 5Barbarian King and Archer Queen must be more than lev 12 In this th9 war attack strategy player need troops combo of
10 Witch1 Golem3 Wizard4 Healer2 Archer And spells combo of
2 Jump spells-1Healing spell-1Rage spell1 PoisonIn Clan castle- 6 Bowlers(Max level) and 1 Poison spell