REST API tutorial
You can access data in Cloud Save using the REST API.
REST APIs provide more flexibility and allow you to automate your workflows by using your favorite language and game development engine or from a game server.
The Cloud Save service provides the following REST APIs:
- Cloud Save Player API for player actions (e.g. saving/loading data)
- Cloud Save Admin API for admin actions (e.g. configuring queries/indexes)
There is a rate limit of 600 requests per player per minute to the Cloud Save service.
Authentication
You can authenticate requests to the Cloud Save REST API using a Multiplay Hosting token or a stateless token. Use the received token as a bearer token for HTTP authentication in the request header.
Authenticating with a Multiplay token from a game server is recommended. Authenticating with a stateless token requires you to create a service account and store the private key securely, whereas Multiplay tokens do not require this and are less complex to manage.
Authenticate using a Multiplay Hosting token
You can retrieve a Multiplay Hosting token by running the following request on the game server:
curl -X GET http://localhost:8086/v4/token
The request would return a response in the format below:
{"token":"<BEARER_TOKEN>", "error":""}
Authenticate using a stateless token
To use a stateless token, you need to create a service account and call the Token Exchange API to obtain a stateless token with a limited lifespan.
Calling the REST API
You can call a module endpoint using any HTTP library that is native to the codebase. Use the retrieved authentication token as a bearer token for HTTP authentication in the request header.
An example CURL request to save data to a player could look like this:
curl -X POST
-H 'Authorization: Bearer <BEARER_TOKEN>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"key":"someKey","value":"someValue"}' \
'https://cloud-save.services.api.unity.com/v1/data/projects/<PROJECT_ID>/players/<PLAYER_ID>/items'