This is an old revision of the document!


Below is the most basic thing you will need for starting API requests. Note: Currently this is only in python, if you are using something like javascript you will have to adapt this code to that language.

If you are interested in tying this in with a discord bot, you can check Fivemans Bot Github for examples, and ways to use the api. Note: It was written in python

Another Note: This is all for python 3.8.3+, I have no idea if this will work for earlier versions, or even later versions in some cases

Basic interacting with API
import requests # requests is a library that allows us to interact with a site
api_key = "api_key_goes_here" # variable name, makes things easier
headers = {"api-key": api_key} # headers are where you store the api-key for this API, this can be different for other sites or games API, make sure to read the documentation about it
params = {
    'game': 1, # these are the parameters, almost all api requests will need some sort of parameters to work, for this request we only need to specify which game we want
}
# note: the games and styles are all integer values, check https://wiki.strafes.net/api for more info about these
 
response = requests.get("https://api.strafes.net/v1/map", headers=headers, params=params) # the actual part that will interact with the site
r = response.json() # this will make the response readable, if you do not add this it will only display the response code. Ex: <response: [200]> if the request was valid
API Requests with user input
import requests
from pprint import pprint # this is just to make print look nice, not needed
api_key = "api_key_goes_here"
headers = {"api-key": api_key}
 
style = input("What style would you like to use?")
game = input("What game would you like to use?")
 
params = {
    'style': style
    'game': game
    'whitelist': True # theres a few cases where players with default status can get into this request with cheated times, so this is to prevent that
}
 
response = requests.get("https://api.strafes.net/v1/time/recent/wr", headers=headers, params=params)
r = response.json()
pprint(r)
Navigation