Last week, I went through the players endpoint in the WP REST API and how you can get, add, update and delete players. Today, I’m going to do the same for teams.
Getting teams
The teams endpoint is /sportsbench/teams. And in order to tell you how to get teams, I first need to tell you the available fields that will appear when you make a GET request. They are:
- team_id
- team_name
- team_location
- team_nickname
- team_abbreviation
- team_city
- team_state
- team_head_coach
- team_division
- team_slug
- team_active
From here, you can search for teams using any of these fields.
Adding, updating and deleting teams
In terms of adding, updating and deleting teams, it’s also pretty simple once you know what you’re doing.
When you’re adding a team, you don’t need to specify a team id. That will get assigned automatically. Also, you don’t need to specify every field for a team, similar to the normal add team page in the WordPress backend.
Obviously, you will need the player id for updating and deleting teams.
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!
Leave a Reply