Cloud Services API package

Hello everyone,

We are happy to announce the official release of the new Cloud Services Apis package (1.0.1)!
This API package provides low-level access to our public apis to enable advanced use cases.

Here’s a video explaining the purpose of the package:
VIDEO

The package documentation can be found here: Unity Cloud Services APIs
This package is available in the package manager.

Examples of capabilities that this enables:

  • Access to Admin Apis
  • Build custom editor tooling
  • Run operations with server authority
  • Extend Game Client functionality

This package integrates well with Unity-driven dedicated servers.

The package also comes with many editor samples and tutorials to showcase the type of tools you can build (see the vid).
They are available through the “Services/API Samples” menu item.

We are looking forward to your feedback!

5 Likes

Hello @GabKBelmonte

That sounds great!

Is there a tutorial on how to sync the api samples? I added my projectID in the settings tab but it didn’t do anything. I only see the code snippets on each pages, not the input text and buttons.

Hi.

Did you enter a value for every setting?
The samples currently require every field in the settings to be entered.

I haven’t done that. I will try thanks!

Hi Erickb!

So I searched and I was not able to find thoses keys: AdminKeyIdentifier, AdminKeySecret, TrustedKeyIdentifier and TrustedKeySecret. I am a solo dev so I have full admin access.

image

Hi, these are service account information that is required to run the admin & trusted clients APIs.
The service accounts need to be configured with the right permissions for the operations you want to allow. You can enter the same key for both if you want.

1 Like

Hi ,
Is there a way to get the metadata of leaderboard entries when requesting scores?

I’m using the package to remove invalid scores from our leaderboards, currently just filtering by the score itself, but we also have some entries without any metadata, which probably aren’t coming from the game itself either.

Thanks

Found a way to include the metadata in the request in the normal services APIs, doesn’t seem to be available in the admin ones.

But i’m now getting the following error when trying to request scores with their metadata:
The requested scores all have valid metadata entries.
If i change the includeMetadata parameter to false, it works correctly.

Code:

var clientC = ApiService.CreateGameClient();
var responseC = await clientC.SignUpAnonymously(projectId);
var apiC = clientC.Leaderboards;

var scores = await apiC.GetLeaderboardScores(projectId, "0", true, null, 10);

Error:

Deserialization of type 'Unity.Services.Apis.Leaderboards.LeaderboardScoresPage' failed.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'results[0].metadata', line 1, position 184.
  at Newtonsoft.Json.JsonTextReader.ReadStringValue (Newtonsoft.Json.ReadType readType) [0x002d8] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonTextReader.ReadAsString () [0x00000] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x000c2] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues (Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x000cb] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor`1[T] creator, System.String id) [0x000b2] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) [0x0008b] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00148] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList (System.Collections.IList list, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id) [0x00173] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) [0x000dc] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0007f] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues (Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00128] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.Serialization.ObjectConstructor`1[T] creator, System.String id) [0x000b2] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract objectContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, Newtonsoft.Json.Serialization.JsonProperty containerProperty, System.String id, System.Boolean& createdFromNonDefaultCreator) [0x0008b] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00148] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <761cf2a144514d2291a678c334d49e9b>:0 
  at Unity.Services.Apis.WebRequestUtils.ProcessObjectResponse[T] (UnityEngine.Networking.UnityWebRequest request, Unity.Services.Apis.ApiResponse`1[T] response) [0x0002a] in .\Library\PackageCache\com.unity.services.apis@bdc0d9d02614\Runtime\Network\WebRequestUtils.cs:123 
UnityEngine.Debug:Log (object)
LeaderboardInvalidScoreRemoval/<Test3>d__6:MoveNext () (at Assets/LeaderboardInvalidScoreRemoval.cs:48)
System.Threading.Tasks.TaskCompletionSource`1<Unity.Services.Apis.ApiResponse`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>>:SetResult (Unity.Services.Apis.ApiResponse`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>)
Unity.Services.Apis.ApiOperation`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>:SetTaskResult (Unity.Services.Apis.ApiResponse`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>) (at ./Library/PackageCache/com.unity.services.apis@bdc0d9d02614/Runtime/Generated/Shared/ApiOperation.cs:168)
Unity.Services.Apis.ApiOperation`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>:Complete (Unity.Services.Apis.ApiResponse`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>) (at ./Library/PackageCache/com.unity.services.apis@bdc0d9d02614/Runtime/Generated/Shared/ApiOperation.cs:145)
Unity.Services.Apis.ApiClient/<>c__DisplayClass26_0`1/<<Send>b__0>d<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>:MoveNext () (at ./Library/PackageCache/com.unity.services.apis@bdc0d9d02614/Runtime/Network/ApiClient.cs:155)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start<Unity.Services.Apis.ApiClient/<>c__DisplayClass26_0`1/<<Send>b__0>d<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>> (Unity.Services.Apis.ApiClient/<>c__DisplayClass26_0`1/<<Send>b__0>d<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>&)
Unity.Services.Apis.ApiClient/<>c__DisplayClass26_0`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>:<Send>b__0 (Unity.Services.Apis.ApiResponse`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>)
Unity.Services.Apis.WebRequestUtils:OnCompleted<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage> (System.Action`1<Unity.Services.Apis.ApiResponse`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>>,UnityEngine.Networking.UnityWebRequest,System.Threading.CancellationTokenRegistration) (at ./Library/PackageCache/com.unity.services.apis@bdc0d9d02614/Runtime/Network/WebRequestUtils.cs:66)
Unity.Services.Apis.WebRequestUtils/<>c__DisplayClass1_0`1<Unity.Services.Apis.Leaderboards.LeaderboardScoresPage>:<SendWebRequest>b__1 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.apis@bdc0d9d02614/Runtime/Network/WebRequestUtils.cs:22)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()

Hey!
Looking at the callstack and our latest doc it looks like metadata is incorrectly set as a string.

If you know how to embed a unity package, all you have to do is change the string to an object.

        [DataMember(Name = "metadata", EmitDefaultValue = false)]
        [Preserve]
        public string Metadata { get; set; } //this is probably a `string` in your current version

In the file Packages/com.unity.services.apis/Runtime/Generated/Game/Leaderboards/Model/LeaderboardEntry.cs
It is already fixed in the current head of the repository, so we’re just missing a release of the package.
This will be a major release due to breaking changes (like this one) so wont be out quickly.

Mind you, in the next version, the admin API will also already support metadata out of the box in the file
Packages/com.unity.services.apis/Runtime/Generated/Admin/Leaderboards/Model/LeaderboardEntry.cs, so you might be able to just add it there as well and it might work without having to use the game api?

I will let the team responsible know.

Cheers!