Results 1 to 4 of 4

Thread: FAQ & Guide to the API

  1. #1

    Join Date
    Jun 2015
    Location
    Stealing your DE
    Posts
    735

    Cool FAQ & Guide to the API

    API: First Steps & FAQ


    The whole community is still super excited about the API. However, a numerous amount of users, don’t got everything. So I decided to post a basic guide and anser some frequently asked questions

    FAQ


    What is the API doing?

    The API gives developers access to in game data, for example the member list of a clan

    Why do we need an API?

    The API gives developers the chance to create apps and websites with information from the game. This is useful for example to create clan websites showing the clan’s information, member list with donations and information about the last 50 wars.
    Also, you can get local (any country) and global top-200 lists for clans and players. Additionally, you can use a list of all Legend players.

    How do I get access to the API?

    To access the api:
    1. Go to developer.clashofclans.com
    2. Create an account and confirm your E-Mail addres


    How can I query the API?

    For querying the API, you need 2 things: A valid token and the correct URL

    For the URL, go to the documentation and look for the query you need. Each query has a special URL, you’ll need.

    A Key can be created using “My account”. Note that you’ll have to enter the IP(‘s) you want to access the API from. For testing you can simply enter your current IP (getip.com).

    If you want to use your script public, you’ll have to create a server with a static IP address. To find out your server’s IP change the request URL to https://ifconfig.io (only works when you've used cURL)
    How can I make scripts for the API?

    The easiest way to create scripts is using Apache (XAMPP combines multiple features, download it at https://www.apachefriends.org/index.html), so you are able to simulate the server on your Computer and needn’t upload it to a server to check every time.

    Basic Scripts for the API

    Basic request with cURL:

    PHP Code:
     <?php
    // Replace with the token you get from the site, see more at http://jwt.io
    $accesstoken 'ABC.XYZ.MEO';

    //Use the first url to test your Server's IP adress and cURL function
    //$url = 'https://ifconfig.io';
    $url 'https://api.clashofclans.com/v1/leagues';
    $ch curl_init(htmlspecialchars($url));

    $headr = array();
    $headr[] = 'Accept: application/json';
    $headr[] = 'Authorization: Bearer '.$accesstoken;

    curl_setopt($chCURLOPT_HTTPHEADER$headr);
    curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);

    $execute curl_exec($ch);
    var_dump($execute);
    ?>

    If you don't want to use cURL or of you are not sure that it will work, use this one:

    PHP Code:
    $request_URL"abc" //Your request URL
    $api_token"..." //Your API Token
    $result file_get_contents($request_URLnullstream_context_create(array(
                    
    'http' => array(
                    
    'method' => 'GET',
                    
    'header' => 'Accept: application/json' "\r\n"
                    
    'Authorization: Bearer ' $api_token "\r\n",
                    ),
                    )));
               
    // decodes the result into a useable array
                    
    $data_json json_decode($result,true); 

    If you want, you can PM me some basic scripts you created and I'll place them here.

    Common problems and fixes


    I get Error 403 every time I want to make a query!

    Error 403 is caused due of incorrect or missing authorization:
    Have you mistyped the token? Copy it again from developers.clashofclans.com
    Has your server changed his IP or have you entered the wrong one? Replace the URL with www.ifconfig.io to find out server's IP:

    If you are working locally with Apache, check your IP Address using getip.com
    If these things don’t work, your script’s query is incorrect, try to use a method from above

    Error 404

    If you get Error 404, you have probably entered a wrong request URL or an invalid clan tag/location ID/league ID

    Error 400

    Error 400 means that you haven’t provided all information the server needs to complete your request. Look in the documentation and be sure you entered all required information. Also check if there’s not a misspelling in your script!

    Error 429

    Error 429 tells you, that there are too many requests for your key. As Jafu pointed out, there are two limits, one for requests per second and one for requests per minute. Simply retry it after one second.
    If this keeps happening on your server, you’ll have to create several keys and randomly choose between them.

    Error 500

    Error 500 is an unknown error, simply retry. This might be caused due of an Error 400, so also check if your query was correct. If this doesn’t help, write a bug report.

    Error 503

    When Error 503 occurs, the API is under maintaince at the moment. This can sometimes take some hours. To avoid having no data available, cache it.


    Thanks for reading (I hope I haven't done too many mistakes). If you have any improvement ideas to this quide, answer and I'll do my best
    Last edited by WernerDerChamp; June 6th, 2016 at 03:33 PM. Reason: bugfix
    Werner der Champ German CoC Wiki Admin (Link)
    My Ideas:Matchmaking fix for Legends|Cat troop idea|Ultimate Clash Royale Tournament idea
    Quote Originally Posted by WernerderChamp View Post
    Are you again waiting till 100,000,000 total clicks on "Try again" ?

    Quote Originally Posted by Stitch View Post
    Yes. Please hurry up with the final 10,000 taps!


  2. #2
    Should be made as a sticky Thread instead of the current one.
    $DOLLAR AKSHAY$
    Visit my Personal Website at http://dollarakshay.com/

  3. #3

    Join Date
    Jun 2015
    Location
    Stealing your DE
    Posts
    735
    Quote Originally Posted by DollarAkshay View Post
    Should be made as a sticky Thread instead of the current one.
    I would like to see it as a sticky, but at first I will improve it a bit.

    Also I've recorded a video about the API, might upload it at the weekend
    Werner der Champ German CoC Wiki Admin (Link)
    My Ideas:Matchmaking fix for Legends|Cat troop idea|Ultimate Clash Royale Tournament idea
    Quote Originally Posted by WernerderChamp View Post
    Are you again waiting till 100,000,000 total clicks on "Try again" ?

    Quote Originally Posted by Stitch View Post
    Yes. Please hurry up with the final 10,000 taps!


  4. #4
    Centennial Club
    Join Date
    Dec 2014
    Posts
    115
    Quote Originally Posted by WernerDerChamp View Post
    I would like to see it as a sticky, but at first I will improve it a bit.

    Also I've recorded a video about the API, might upload it at the weekend
    Want me to correct all your spelling mistakes ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •