Public API's For Non-Developers

Given recent discussions, and personal talks with other players, it seems a lot of people are having trouble using the API’s as well as a lot of complains like “Is not fair if a team doesn’t have a developer”. I’ve decided to create api’s for everyone to use as simple as possible and if you are willing to put the time, you will defiantly be able to make something out of it for your team.

The contribution api is missing for now since is only available after a team gives permission to use it.

Here is a simple explanation to each API (I will go into more detail another day if needed)


Get Single Team Info

https://www.wdscripts.com/api/teams/team_info?id=team

Change the last ‘team’ to the whatever team you are trying to get the info for.


Get Teams Metadata (same info as above but for every team in atlas)

https://www.wdscripts.com/api/teams/metadata-teams

No parameters here.


Get Castles Metadata

https://www.wdscripts.com/api/castles/metadata-castles

No parameters here, outputs all the castles in atlas.


Get Single/Multiple Castles

https://www.wdscripts.com/api/castles/castle_info?id=castleid

Replace ‘castleid’ with any ‘id’ given by the castle metadata above.

For Multiple Castles you can simply add a comma after each ‘id’ like this:

https://www.wdscripts.com/api/castles/castle_info?id=castleid,castleid

It will only take the first 100 castles into consideration so dont go above that



Anyways given these API’s all you really need to do is parse json text into a file/tool which is very simple and even if you are not a programmer, as long as you put the time, you will get it. I suggest using python if you are gonna do it for the first time.

10 minute video on installing pycharm (A development enviroment for Python)

Video

https://www.youtube.com/watch?v=YxHplztMQMc

and here is a very short and simple tutorial on how to get started with json in python.

https://www.w3schools.com/python/python_json.asp

Code Example:

Python
import json
from urllib.request import urlopen

# Declaring the api's

api_single_team = "https://www.wdscripts.com/api/teams/team_info?id="
api_meta_teams = "https://www.wdscripts.com/api/teams/metadata-teams"

api_meta_castles = "https://www.wdscripts.com/api/castles/metadata-castles"
api_castles = "https://www.wdscripts.com/api/castles/castle_info?id="

# Each function below calls their respective api url, adds a parameter (if any) and returns data for it
# You don't actually need to change the functions at all, see main for use


def get_single_team(team):
    with urlopen(api_single_team + team) as apiResponse:
        team_data = json.loads(apiResponse.read())
        return team_data


def get_meta_data_teams():
    with urlopen(api_meta_teams) as api_response:
        team_meta_data = json.loads(api_response.read())
        return team_meta_data


def get_meta_data_castles():
    with urlopen(api_meta_castles) as api_response:
        castles_meta_data = json.loads(api_response.read())
        return castles_meta_data


def get_castles(castle_list):
    # First parse the list into a string with a comma in between each element
    divider = ","
    castles_string = divider.join(castle_list)
    with urlopen(api_castles + castles_string) as api_response:
        castle_data = json.loads(api_response.read())
        return castle_data


def main():

    # Get data from a single Team
    data = get_single_team("ColdBrewCrew")
    print(data)

    # Get data for all teams
    data = get_meta_data_teams()
    print(data)

    # Get data for all castles
    data = get_meta_data_castles()
    print(data)

    # Get data for multiple castles
    list_castles = ['A152-2', 'A152-0', 'A152-1']
    data = get_castles(list_castles)
    print(data)

    # Get data for a single castle
    # Note: Giving that is the same function as multiple castles, you would still need to pass the castle in a list
    list_castles = ['A152-2']
    data = get_castles(list_castles)
    print(data)


main()
Visual Basic
Imports System.IO
Imports System.Net.Http
Imports Newtonsoft.Json.Linq

Module Module1

    Sub Main()

        'Get Team Data
        Dim team_data As String = get_single_team("ColdBrewCrew")
        Dim team_json As JObject = JObject.Parse(team_data)
        Console.WriteLine(team_json)

        'Get castle Data
        Dim castleArray() As String = {"A152-2", "A152-0", "A152-1"}
        Dim castle_data As String = get_castles(castleArray)
        Dim castle_json As JObject = JObject.Parse(castle_data)
        Console.WriteLine(castle_json)

        Console.ReadKey()

    End Sub

    Function get_single_team(team) As String

        Dim api_single_team As String = "https://www.wdscripts.com/api/teams/team_info?id="
        Dim finalUrl As String = api_single_team + team

        Return get_url_response(finalUrl)

    End Function
    Function get_meta_data_team() As String

        Dim api_meta_teams As String = "https://www.wdscripts.com/api/teams/metadata-teams"
        Return get_url_response(api_meta_teams)

    End Function
    Function get_meta_data_castles() As String

        Dim api_meta_castles As String = "https://www.wdscripts.com/api/castles/metadata-castles"
        Return get_url_response(api_meta_castles)

    End Function
    Function get_castles(castle_list) As String

        'Convert array to string (There is likely an easier way for this)
        Dim castleString As String = ""
        For Each castle As String In castle_list
            castleString += castle + ","
        Next
        castleString = castleString.Trim.TrimEnd(",")

        Dim api_castles As String = "https://www.wdscripts.com/api/castles/castle_info?id="
        Return get_url_response(api_castles + castleString)

    End Function

    'Opens and grabs the content of the api
    Function get_url_response(url) As String
        Dim client As HttpClient = New HttpClient()
        Dim Response As HttpResponseMessage = client.GetAsync(url).Result

        Return Response.Content.ReadAsStringAsync().Result
    End Function

End Module
34 Likes

You’re a saint.

1 Like

You the man!

1 Like

This is exactly why PG released the API, just to clarify that for all the haters and whiners. They wanted to have people creating these kind of resource for the community.

Thanks @Napk1n

8 Likes

I hope to start pycharm one day. Still learning basic python in school. Still haven’t reached django yet.

Majored in .Net am currently learning C#

django might look intimidating at first but is quite useful and convenient once you get the hang of it. Though I honestly don’t do much web-development so my experience with django narrows down to a handful of projects.

Nice c# is in my top 3 favs, though I don’t use it as much these days.

Was good of you share this with others like this, as many do not know about APIs or how to use them :hugs: Do not have Atlas yet, so have no use for getting into this until do get it. Still think PG should incorporate this into the game for everyone to be to use as will still be many who are not into technology to make use of the APIs.

Wowza. U may think how’s it possible, but in my school, I am learning python only. Don’t know anything about java, c, c++ or any other languages. Not even basics.

Thanks. Am trying to get a headstart on django before teacher teaches us.
Do u know if I can do practice of django through mobile?
I use pydroid3 for python on android.

Some programs I’ve heard of only teach a single language first semester, along with database (access or sql), hardware class, networking class, math. Just so you get the basics of everything since many students go into it without prior IT knowledge.

If you are in second semester and are still only doing python than that’s an issue in my opinion.

I doubt it.

There is a youtuber by the name of “Derek Banas” that I really like when learning or refreshing my mind on a language, he moves at a good pace, not too slow, not too fast. Give him a try for your django or python endeavors.

Same for myself :wink:

Yep I’m learning MySQL too forgot to mention it sorry.
Okay checking Derek Banas out then

Thank you for sharing this! It levels the playing field a bit more for all other teams - especially new teams that haven’t had time to build connections with those who have these resources.

Edit suggestion^ just so that it’s a bit clearer which ‘team’ to change and to mention that they need to include the capital letters - otherwise the resulting page will be ‘null’.

added this.

My bad I sort of rushed this yesterday. It will now work either way.

Also if the team you input does not exist, it will grab the closest team to the given string, example:

`https://www.wdscripts.com/api/teams/team_info?id=dreadn`

Should return info for DREADNOUGHT.

4 Likes

Tested and it works! Thanks again :grin:

Very nice and I’m sure appreciated by many!

In case anyone wants to help me, not looking for handouts but if you’re feeling generous,

If I try using the URL for team info, I get a few errors:

Screenshot

image

Here is the code that generates that:

Screenshot

image

If I copy the text from the url output and paste it in, and change all the single quotes to double quotes, it seems to work fine:

Screenshot

image
image

Any suggestions? I’m sure I’m just doing something dumb when trying to import the URL.

1 Like

What…is… happening? @_@

The URL Napk1n posted just needs to be copy-pasted into your internet browser with the suggested edit.

try copy pasting this:
https://www.wdscripts.com/api/teams/team_info?id=WeLive4War

@Daedalus is a mistake on my end actually, ill fix it in a bit

1 Like