Players and the REST API
WP REST API
In 2017, the WP REST API made its debut inside of WordPress core. This meant that data from your WordPress site could be accessed and changed from outside of your domain if you wanted to do that.
Likewise, Sports Bench has extended the regular REST API to include Sports Bench data. These next series of posts will go over how to use the REST API for each of the data tables in Sports Bench.
Today we’ll go over the players REST API. And before we begin, I’m assuming you know how to use REST APIs to create, read, update and delete data.
In order to tell you how to get players, I first need to tell you the available fields that will appear when you make a GET request. They are:
From here, you can search for players using any of these fields. This is great when you need to pick all the players for a team or are using a player name search that runs on every key stroke. Pretty simple stuff.
Adding, updating and deleting players
In terms of adding, updating and deleting players, it’s also pretty simple once you know what you’re doing.
When you’re adding a player, you don’t need to specify a player id. That will get assigned automatically. Also, you don’t need to specify every field for a player, similar to the normal add player page in the WordPress backend.
Obviously, you will need the player id for updating and deleting players.
Other than that, there’s not too much more to this.
What can you do with this?
Realistically, you can do just about anything you want with this and the REST API. You can create separate web applications or create a mobile application for your league and call in data from the website.
The possibilities are endless, and that’s the best part of the REST API. You can do really cool things and not have to write thousands of lines of code. So have fun with it!