Skip to main content

Save Data

API for saving player's game data to the cloud.

URL Verification

This API uses the service-storage-api.playnanoo.com domain.

API Information

  • URL: https://service-storage-api.playnanoo.com/storage/v20221001/save
  • Method: PUT
  • Authentication Required: Yes
DeviceInfo Inheritance

The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.

Request Parameters

ParameterTypeRequiredDescription
storage_keystringRequiredKey of the data to save
storage_valuestringRequiredValue of the data to save (JSON string possible)
isPrivatestringRequiredData access restriction setting (on/off) - When set to on, blocks external players from accessing the data

Response Data

Res Class

FieldTypeDescription
StatusstringProcessing status

Unity C# Implementation

BaseResponse Class

Base class for all API responses.

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

Field descriptions:

  • ErrorCode: Error code
  • Message: Error message
  • WithdrawalKey: Key required for recovery if account is in withdrawal grace period (provided only for accounts in withdrawal grace period)
  • BlockKey: Key provided if account is blocked (provided only for blocked accounts)

Save Data Class

using System;
using System.Collections;
using UnityEngine.Networking;

public class StorageSave
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20221001/save";

[Serializable]
public class Req : DeviceInfo
{
public string storage_key; // Key of the data to save
public string storage_value; // Value of the data to save
public string isPrivate; // Blocks external players from accessing the data when access restriction is set

public IEnumerator Send(string storage_key, string storage_value, bool isPrivate, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(storage_key)) this.storage_key = storage_key;
if (!string.IsNullOrEmpty(storage_value)) this.storage_value = storage_value;
this.isPrivate = isPrivate ? "on" : "off";

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public string Status;
}
}

Usage Example

public void SaveGameData()
{
StorageSave.Req req = new StorageSave.Req();

// Serialize game data to JSON
var gameData = new
{
level = 10,
score = 1000,
items = new[] { "sword", "shield", "potion" }
};
string jsonData = JsonUtility.ToJson(gameData);

StartCoroutine(req.Send(
storage_key: "player_game_data",
storage_value: jsonData,
isPrivate: false, // Save as public data
onSuccess: res =>
{
Debug.Log("Data save successful");
},
onError: error =>
{
Debug.LogError($"Data save failed: [{error.ErrorCode}] {error.Message}");
}
));
}
Data Format

Since storage_value is a string, it is recommended to serialize complex data structures as JSON for storage.

Auto-save

It is recommended to save game data at important points (level up, item acquisition, etc.). Check network status and implement retry logic in case of save failure.