Getting started
Welcome to the papergames.io API documentation! This guide will walk you through the steps to integrate the API into your application and start initiating one-on-one game sessions.
Duration: ⏱️ 5 minutes
Creating an API key
Getting an API key is easy and can be done through the developer tools. You need to register with a valid email address or through social Logins.
- Visit the developer tools and click on "Create API Key" to generate a new API key.
- Fill in the form with your application API key name, for example the environment where you will use the API key (Development, Staging, Production).
- Copy the generated API key and store it in a secure place. You will need it to authenticate your requests.
Test your API Key
All your requests to the API must include the X-Api-Key
header that includes your API key. The easiest way to quickly
test is through the endpoint tester. Take some time to explore the
API endpoints.
- Click on the
Authorize
button on the top right corner and paste your API key.
- Click on the
POST
/api/v2/game-session/player-vs-player
to create a player vs player game session. - Go ahead and click on the Try it out button, have a look at the
JSON
payload that will be sent. - Click on the Execute button to send the request.
- The endpoint returns two URLs that can be embedded in your application to connect two players.
{
"uid": "{uid}",
"playUrl": "https://papergames.io/en/r/{uid}/embed/play",
"watchUrl": "https://papergames.io/en/r/{uid}/embed"
}
The playUrl
field contains an embeddable URL that can be integrated into an iframe for a user to play.
The watchUrl
field contains an embeddable URL that can be integrated into an iframe for a user to watch the game as a spectator.
The uid
field contains the identifier for the game session. It can be combined with webhooks to update your system with the game score.
Embedding URLs
Once you know how to make API requests, you can proceed with a quick integration test (~5 minutes).
Initiate a game session for Player 1
- Call the API endpoint Create a player vs player game session on the endpoint tester.
- Open our Codepen playground. You'll see a form and iframe placeholder.
- Copy the
playUrl
field provided by the API response (step 1) and paste its value on the Play url form field. - Fill in the Username field with John Doe, or any dummy username.
- Click on the Set iframe URL. The iframe initiates a game session on papergames.io and prompts the user with a Waiting message.
At this point, the first player is joined to a game session and will wait for another player to join.
Join the game session with Player 2
- Open a new private navigation tab on your browser.
- Repeat the steps 2 to 5 of the Initiate a game session for Player 1 section.
- When you click on the Set iframe URL, player 2 joins the session, and the players can play together.
Integration overview
Conclusion
Congratulations! You have successfully finished this quick introduction and now have a basic understanding of how to implement
our games on your platform.
If you have any questions or encounter issues, feel free to contact us. Happy gaming!