Arnau Castillo avatar image
Arnau Castillo asked

Update Statistic: invocation of cloud script function failed

Hi, I am trying to update an statistic with an Azure Function (which I think it is fine). I don't manage to solve this problem.

This is the azure function, which I can publish without a problem. If I publish another function that only returns the name and time it works fine. The problem is with the request to update the statistic.

Azure function:

namespace FuncionRankingPrueba1
    public static class RankingPrueba
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
            string name; 
            string time; 
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = data?.FunctionArgument?.name;
            time = data?.FunctionArgument?.time;
            int timeint=  int.Parse(time);

            var request = new UpdatePlayerStatisticsRequest
                PlayFabId = data.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                Statistics = new List<StatisticUpdate>
                new StatisticUpdate
                    StatisticName = name,
                    Value = timeint
            var apiSettings = new PlayFabApiSettings
                TitleId = data.TitleAuthenticationContext.Id,
                DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process),
            var serverApi = new PlayFabServerInstanceAPI(apiSettings);
            return await serverApi.UpdatePlayerStatisticsAsync(request);

This is the call from my project, where Prueba3Arnau is the name of the function in Playfab, Level1Times is the statistic name I want to update and time is the integer to pass:

   public void UpdateLeaderBoard()
        PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest()
            Entity = new PlayFab.CloudScriptModels.EntityKey()
                Id = PlayFabSettings.staticPlayer.EntityId, 
                Type = PlayFabSettings.staticPlayer.EntityType, 
            FunctionName = "Prueba3Arnau", 
            FunctionParameter = new {name= "Level1Times", time="21"},
            GeneratePlayStreamEvent = false 
        }, (ExecuteFunctionResult result) =>
            Debug.Log($"The {result.FunctionName} function took {result.ExecutionTimeMilliseconds} to complete");
            Debug.Log($"Result: {result.FunctionResult.ToString()}");
        }, (PlayFabError error) =>
            Debug.Log($"Opps Something went wrong: {error.GenerateErrorReport()}");

This is the error

If I go to the second .cs (Assets/PlayFabSDK/Shared...), line 260, this is where it goes:

I don't know if it has something to do with the secret key, a permit that I have to grant or what.


apisCloudScriptLeaderboards and Statistics
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Arnau Castillo avatar image Arnau Castillo commented ·

The error is here:

And this is the line 260 of the second .cs

0 Likes 0 ·
error1playfab.png (34.8 KiB)
error2playfab.png (58.5 KiB)

1 Answer

Gosen Gao avatar image
Gosen Gao answered

You can follow Tutorial: Debugging CloudScript using Azure Functions with the Azure portal to check the streaming logs for troubleshooting. If there are no logs in the logstream, there may be something incorrect when registering the function to PlayFab. As the document of Azure Function mentioned, "Functions lets you use keys to make it harder to access your HTTP function endpoints during development. Unless the HTTP access level on an HTTP triggered function is set to anonymous, requests must include an API access key in the request." Since you are using Function level, please check your URL to see if it has the API access key.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.