question

kelevsaviano avatar image
kelevsaviano asked

HTTP/1.1 400 Bad Request calling GetUserData

Hello, I'm trying to save and load user data following THIS GUIDE.

No problem when I save them but I keep getting HTTP/1.1 400 Bad Request error every time I try to load some.

This is the guide code for saving data:

void SetUserData() {
    PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest() {
        Data = new Dictionary<string, string>() {
            {"Ancestor", "Arthur"},
            {"Successor", "Fred"}
        }
    },
    result => Debug.Log("Successfully updated user data"),
    error => {
        Debug.Log("Got error setting user data Ancestor to Arthur");
        Debug.Log(error.GenerateErrorReport());
    });
}

This is the guide code for loading data:

void GetUserData(string myPlayFabeId) {
    PlayFabClientAPI.GetUserData(new GetUserDataRequest() {
        PlayFabId = myPlayFabeId,
        Keys = null
    }, result => {
        Debug.Log("Got user data:");
        if (result.Data == null || !result.Data.ContainsKey("Ancestor")) Debug.Log("No Ancestor");
        else Debug.Log("Ancestor: "+result.Data["Ancestor"].Value);
    }, (error) => {
        Debug.Log("Got error retrieving user data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

There is no clue on which value should replace "myPlayFabeId" but I'm guessing it should be the User ID from which get the data, even if there is no mention on it in the saving data code. So I tried both User ID and App ID, but I just keep getting that error.

This is how I am saving the data (it works just fine):

public static void SaveData(string p_key, string p_data)
{
        if (!ConnectionManager.Connected)
            return;

        PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest()
        {
            Data = new Dictionary<string, string>() 
            {
                {p_key, p_data}
            }
        },
        result => 
        {
            Debug.Log($"PlayFab Saved {p_key} = {p_data}");
        },
        error => 
        {
            Debug.Log($"Got error setting user data {p_key} to {p_data}");
            Debug.Log(error.GenerateErrorReport());
        });
}

This is how I am loading the data:

public static string LoadData(string p_key)
{
        string _result = "";

        if (!ConnectionManager.Connected)
        {
            return "";
        }

        PlayFabClientAPI.GetUserData(new GetUserDataRequest()
        {
            PlayFabId = PlayFabAPIManager.EntityID,
            Keys = null
        }, 
        result => 
        {
            //Debug.Log("Got user data:");

            if (result.Data != null && result.Data.ContainsKey(p_key))
            {
                _result = result.Data[p_key].Value;
            }
            else
            {
                Debug.Log($"No data found for {p_key} key");
            }
        }, 
        (error) => 
        {
            Debug.Log($"Got error retrieving user data:{error.ErrorMessage}");
        });

        return _result;

}

I think that's some problem with the GetUserData method or the GetUserDataRequest constructor because the compiler goes straight to the error handling.

,

Hello, I'm trying to save and load user data following THIS guide.

No problem for saving the data but I keep getting HTTP/1.1 400 Bad Request anytime I try to load them.

This is the suggested data lading code:


void GetUserData(string myPlayFabeId) {
    PlayFabClientAPI.GetUserData(new GetUserDataRequest() {
        PlayFabId = myPlayFabeId,
        Keys = null
    }, result => {
        Debug.Log("Got user data:");
        if (result.Data == null || !result.Data.ContainsKey("Ancestor")) Debug.Log("No Ancestor");
        else Debug.Log("Ancestor: "+result.Data["Ancestor"].Value);
    }, (error) => {
        Debug.Log("Got error retrieving user data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

There is no clue on which value should replace "myPlayFabeId" but I'm guessing it should be the UserID from which must load the data, even if it is not specified inside the data saving code.

This is the suggested data saving code:

void SetUserData() {
    PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest() {
        Data = new Dictionary<string, string>() {
            {"Ancestor", "Arthur"},
            {"Successor", "Fred"}
        }
    },
    result => Debug.Log("Successfully updated user data"),
    error => {
        Debug.Log("Got error setting user data Ancestor to Arthur");
        Debug.Log(error.GenerateErrorReport());
    });
}

This is how I'm saving data:

public static void SaveData(string p_key, string p_data)

{
        if (!ConnectionManager.Connected)
            return;

        PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest()
        {
            Data = new Dictionary<string, string>() 
            {
                {p_key, p_data}
            }
        },
        result => 
        {
            Debug.Log($"PlayFab Saved {p_key} = {p_data}");
        },
        error => 
        {
            Debug.Log($"Got error setting user data {p_key} to {p_data}");
            Debug.Log(error.GenerateErrorReport());
        });
}

This is how I'm loading them:

public static string LoadData(string p_key)
    {
        string _result = "";

        if (!ConnectionManager.Connected)
        {
            return "";
        }

        PlayFabClientAPI.GetUserData(new GetUserDataRequest()
        {
            PlayFabId = PlayFabAPIManager.EntityID,
            Keys = null
        }, 
        result => 
        {
            //Debug.Log("Got user data:");

            if (result.Data != null && result.Data.ContainsKey(p_key))
            {
                _result = result.Data[p_key].Value;
            }
            else
            {
                Debug.Log($"No data found for {p_key} key");
            }
        }, 
        (error) => 
        {
            Debug.Log($"Got error retrieving user data: {error.ErrorMessage}");
        });

        return _result;
    }
Player Dataunity3dsdkssupportcommunity
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

·
JayZuo avatar image
JayZuo answered

PlayFabId is the is the PlayFabId returned in LoginResult. For example, the PlayFabId returned in LoginWithCustomID method. PlayFabId is also the master_player_account ID when using in Entity API. Please note, the ID of LoginResult.EntityToken.Entity.Id is title_player_account ID and this is also usually the ID used in Entity APIs. For more details, please see Available Built-In Entity Types - PlayFab | Microsoft Docs.

For Client/GetUserData, as the documentation said, the PlayFabId field is optional and defaults to yourself if not set. So, to get the data you've saved, you can simply ignore it. See https://docs.microsoft.com/en-us/rest/api/playfab/client/player-data-management/getuserdata?view=playfab-rest#request-body.

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.

kelevsaviano avatar image kelevsaviano commented ·

Yeah I figure this out last night, I was using EntityToken.Entity.Id Instead of PayFabId.

Thank you for all the useful info!

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.