Skip to main content

Multi Save Data

API for saving multiple game data items at once.

URL Verification

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

API Information

  • URL: https://service-storage-api.playnanoo.com/storage/v20221001/save/multi
  • 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_itemsstringRequiredList of data to save (JSON string)

StorageMultiSaveParam Structure (Convert to JSON before sending)

FieldTypeRequiredDescription
ItemsStorageItems[]RequiredArray of data to save

StorageItems Structure

FieldTypeRequiredDescription
StorageKeystringRequiredKey of the data to save
StorageValuestringRequiredValue of the data to save
IsPrivateboolRequiredWhether the data is private

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)

StorageMultiSaveParam Class

[Serializable]
public class StorageMultiSaveParam
{
public List<StorageItems> Items = new List<StorageItems>();
}

[Serializable]
public class StorageItems
{
public string StorageKey;
public string StorageValue;
public bool IsPrivate;
}

Multi Save Data Class

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

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

[Serializable]
public class Req : DeviceInfo
{
public string storage_items; // Pass StorageMultiSaveParam as JSON string

public IEnumerator Send(string storage_items, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(storage_items)) this.storage_items = storage_items;

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 SaveMultipleData()
{
StorageMultiSave.Req req = new StorageMultiSave.Req();

// Save multiple data at once
StorageMultiSaveParam param = new StorageMultiSaveParam();

param.Items.Add(new StorageItems
{
StorageKey = "player_level",
StorageValue = "10",
IsPrivate = true
});

param.Items.Add(new StorageItems
{
StorageKey = "player_gold",
StorageValue = "5000",
IsPrivate = false
});

param.Items.Add(new StorageItems
{
StorageKey = "player_inventory",
StorageValue = "[sword, armor]",
IsPrivate = false
});

string json = JsonUtility.ToJson(param);

StartCoroutine(req.Send(
storage_items: json,
onSuccess: res =>
{
Debug.Log("Multi data save successful");
},
onError: error =>
{
Debug.LogError($"Multi data save failed: [{error.ErrorCode}] {error.Message}");
}
));
}
Efficient Saving

When you need to save multiple data items simultaneously, using this API can reduce the number of network requests, making it more efficient.

Transactions

All data is saved atomically. If even one fails, the entire operation is treated as failed.