Introduction
In this sample there is nothing to interact with. Using the Player Management API the provided code updates a filtered set of players using an HTTP PATCH
method, then automatically publishes the updated players.
As with all API samples, it is strongly recommended you first study the Learning Guide: Using the REST APIs to provide a basis on which to build more REST API knowledge.
The CodePen is supplied as way to view the code discussed later in the document.
See the Pen 18693-player-management-api-sample-programmatically-update-players by Brightcove Learning Services (@rcrooks1969) on CodePen.
Application flow
The basic logic behind this application is:
- Retrieve all players from a specified account, then filter the set of players to those you wish to update.
- Build an array with the IDs of the filtered set of players.
- Define the updates desired on the filtered set of players, the request that each player be updated accordingly.
- Publish each of the updated players.
Retrieve a filtered set of players, and build an array of their IDs
Find the code which is labeled:
// +++ Configure the request to get players and extract their IDs +++
After defining the options to pass to the proxy to get all players from a specified account, JavaScript's array filter
function is used with the custom filter_players
function to filter the player set. You then loop over the filtered set and push their IDs into another array. Finally you call the function that requests that updates be made.
Request the updates be performed on the filtered set of players
Find the code which is labeled:
// +++ Configure the request to update filtered players +++
In the options
object you define the options needed to pass to the proxy. Note that this includes the requestBody
, which defines the actual changes you wish to make on the filtered set of players. You must loop over each of the player IDs in the playerIDsAra
and make the request. Note that the function is called recursively. Finally you call the function that requests the players be published.
Request the updated players be published
Find the code which is labeled:
// +++ Configure the request to publish updated players +++
Here again you loop over the playerIDsAra
array and make requests that the player be published. If not at the end of the array, the function is called recursively.
You can see the app's JavaScript code from this document's corresponding GitHub repo: liveCustomError.js18693-player-management-api-sample-programmatically-update-players.