It's always good practice to make backups of your game configuration as a safeguard for those rare occasions when you lose some settings or data. GameSparks Snapshots provide a great version-control option, but what if someone on your team accidentally deletes a game Snapshot? We've also seen cases in the past where developers have accidentally dropped some Game Data or Runtime data, which is never a good situation.
So you agree that backing up your stuff is a great idea, now how do you go about backing things up? Unfortunately, GameSparks doesn't provide a 1-click solution for exporting your entire game configuration and data, but it can be done in stages either via our REST API or through the game portal.
Before you attempt to work through this article, we'd recommend taking a refresher on our REST API by following our guide here. A full list of requests and schema can be found on our API swagger page. We also recommend downloading Postman as a means to interface with our REST API.
GameSparks has an number of components that will need to be pulled out separately. They can be broadly broken into:
- Game Configuration
- Database - NoSQL and Game Data Service
- Manage Screens
NOTE: From the Cloud Code page, you can quickly export and import Cloud Code scripts - for more details on how to do this, please see this tutorial.
The Game Configuration contains all of your game configuration settings, such as Virtual Goods, Cloud Code, or Leaderboards. Before you request this data in Postman, you'll need to change the Authorization type to Basic Auth and enter your GameSparks Username and Password.
Getting Game Configuration Data
To get this data out of GameSparks, we'll send a GET request in Postman to the following URL:
The response spits out a big JSON blob, which contains your game configuration settings and Cloud Code (in stringified format). Have a look through the response JSON - it should all look pretty familiar to you! This is the data you want to backup offline.
Restoring Game Configuration Data
If you need to restore the Game Configuration to GameSparks in the future, you can simply use the following PATCH request, passing in the JSON as the request body:
Database - NoSQL and Game Data Service
GameSparks uses MongoDB for Metadata and Runtime Collections and the Game Data Service for Game Data. Each data store has two ways to pull out data, but each have their own limitations when extracting data.
You'll need a valid JWT (Java Web Token) to access the NoSql API, the request for which can be found here. Once you have retried the JWT, you need to add it as a Header to your request.
Metadata and Runtime Collections
The request to access the documents in a collection can be found here: https://docs.gamesparks.com/api-documentation/rest-apis/nosql.html#!/mongo/findUsingPOST
Have a look at the body for this request. You'll need to provide it with the following schema:
- A query is limited to returning 1000 documents at a time (hence the "limit" : 1000). If you have 3000 documents, you would need to do send this request 3 times, each time incrementing the "skip" value by 1000.
- You can use the "query" field and the "fields" field to narrow down specific documents you want to extract, or leave them empty to find them all.
You can also export documents from collections via the portal interface by navigating to Data Explorer -> Collections -> Find -> Export. The same rules apply when exporting via the portal interface.
Game Data Service
To access data in the Game Data Service, you need to use a different API - https://docs.gamesparks.com/api-documentation/rest-apis/nosql.html#!/data/queryItemsUsingPOST
As we saw with the MongoDB Collections, there are some limitations with Game Data Service:
- A query is limited to returning 100 documents.
- There's no skip field with the Game Data Service, so you would need to write some custom pagination logic.
You can also export documents from Data Types via the portal interface:
To backup your Manage screens, you will need to send a GET request to get each component - Screens, Snippets and Charts. The requests can be found here - https://docs.gamesparks.com/api-documentation/rest-apis/game-admin.html#/manage
You can also grab them via the portal interface by navigating to Manage -> Admin Screens and clicking the Import/Export button:
Now that you can get everything out of GameSparks, you can safely pack it all up and store it offline.