question

viti-27 avatar image
viti-27 asked

How to make the request for update the player statistics??

Hi, im using Lua.

I create the request

local request1 = { Statistics =
	{
		StatisticName = "points",
		Value = 1
	}
}

but get error

{ --[[0000000002BE2DA0]] error = "InvalidParams", errorCode = 1000, code = 400, status = "BadRequest", errorDetails = { --[[0000000002BE3540]] Statistics = { --[[0000000002BE37B0]] 1 = "The Statistics field is required." } }, errorMessage = "Invalid input parameters"}

for gettin the leaderboard I use

local request= {
	StatisticName = "points",
	StartPosition =0
}

and works well.

I dont know what to do, Can anybody help me?

apisdata
10 |1200

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

1 Answer

·
Seth Du avatar image
Seth Du answered

I am not familiar with Lua, but according to your error report, the format of your request is incorrect, please see the official documentation of Update Player Statistics: https://docs.microsoft.com/en-us/rest/api/playfab/client/player-data-management/updateplayerstatistics?view=playfab-rest, as it indicates that the Statistics property in the request is a list of StatisticUpdate and in your code, Statistics is an Object.

The request should be:

local request1 = { 
  Statistics =
  {
    {
      StatisticName = "points",
      Value = 1
    }
  }
}

Here is my test example:

local pfClient = require("plugin.playfab.client")
local PlayFabClientApi = pfClient.PlayFabClientApi
PlayFabClientApi.settings.titleId = "5130"
  
local loginRequest = {
    -- https://api.playfab.com/documentation/Client/method/LoginWithCustomID
    CustomId = "GettingStartedGuide",
    CreateAccount = true
}
local request1 = {
    Statistics =
    {
        {
            StatisticName = "Point",
            Value = 67
        }
    }
}
PlayFabClientApi.LoginWithCustomID(loginRequest,
    function(result) 
        print("Congratulations, you made your first successful API call!")
        PlayFabClientApi.UpdatePlayerStatistics(request1,
            function(success) print("update success") end,
            function(fail) print("Something went wrong \n" .. fail.errorMessage) end
        )
    end,
    function(error) print("Something went wrong with your first API call.\nHere's some debug information:\n" .. error.errorMessage) end
)


3 comments
10 |1200

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

viti-27 avatar image viti-27 commented ·

Whats the difference from my request??

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ viti-27 commented ·

My request:

local request1 = {   
  Statistics =  
  {    
    {      
      StatisticName = "points",
      Value = 1    
    } 
  }
}

Your request:

local request1 = {
  Statistics =	
  {
    StatisticName = "points",
    Value = 1
  }
}

I add one more set of parenthesis so that Statistics is a list.

0 Likes 0 ·
viti-27 avatar image viti-27 Seth Du ♦ commented ·

oh thanks!

0 Likes 0 ·

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.