question

Antoine Racine avatar image
Antoine Racine asked

TitleId is not taken into account when they are set directly into the request

C# SDK build 1.81.200914

This occurs in `/Client/LoginWithCustomId` at the very least.

public static async Task<PlayFabResult<LoginResult>> LoginWithCustomIDAsync(...) {
...
  PlayFabApiSettings staticSettings = PlayFabSettings.staticSettings;
  if (request != null)
    request.TitleId = request?.TitleId ?? staticSettings.TitleId;
  if (request.TitleId == null)
    throw new PlayFabException(PlayFabExceptionCode.TitleNotSet, "TitleId must be set in your local or global settings to call this method");
  object obj = await PlayFabHttp.DoPost("/Client/LoginWithCustomID", (PlayFabRequestCommon) request, (string) null, (string) null, extraHeaders, (PlayFabApiSettings) null);
...
}

I've omitted a bunch of code, but this is in `PlayFabClientAPI.cs` around line 2655.

The function check if the TitleId is set in the request or in the static settings. So far so good.
However the `instanceSettings parameter is set to null in the `DoPost` call (last param). This make the actual `DoPost` crash because the function can't extract the titleId from the instanceSettings (it's null!) or the global `PlayFabSettings.staticSettings` (because I'm not, and (don't want to) setting it there).

In effect, setting the TitleId in the request is totally useless since it will never be used.

`DoPost()` only extract the full url before calling the internal `_DoPost` with the same params, so I will omit to include it. Here's the internal `_DoPost()` code where it's crashing

private static async Task<object> _DoPost(
  string fullPath,
  PlayFabRequestCommon request,
  string authType,
  string authKey,
  Dictionary<string, string> extraHeaders,
  PlayFabApiSettings instanceSettings = null)
{
  if ((instanceSettings ?? PlayFabSettings.staticSettings).TitleId == null)
    throw new PlayFabException(PlayFabExceptionCode.TitleNotSet, "You must set your titleId before making an api call");
  ITransportPlugin plugin = PluginManager.GetPlugin<ITransportPlugin>(PluginContract.PlayFab_Transport, "");
  Dictionary<string, string> headers = new Dictionary<string, string>();
  if (authType != null && authKey != null)
    headers[authType] = authKey;
  if (extraHeaders != null)
  {
    foreach (KeyValuePair<string, string> extraHeader in extraHeaders)
      headers.Add(extraHeader.Key, extraHeader.Value);
  }
  return await plugin.DoPost(fullPath, (object) request, headers);
}

Instance setting is always null here, so it's throwing with a `TitleNoSet` exception.

I can provide more details if needed.

Thank you,

sdks
10 |1200

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

Antoine Racine avatar image
Antoine Racine answered

Hi, I call the api with the following format:

var result = await PlayFabClientAPI.LoginWithCustomIDAsync(new LoginWithCustomIDRequest
{
    CreateAccount = shouldCreate,
    CustomId = playfabCustomId,
    TitleId = _options.TitleId
});

Either setting the global settings or creating an instance of the ClientApi with the TitleId works as expected.

It is however still a bug (or very confusing and not reflected in the documentation if it's the intended working) that the TitleId is never taken into account when setting it directly in the request on the static version of the skd.

It seem that the request TitleId is taken into account when calling the method from an instance of the api, overriding the value set in the instance.

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.

Citrus Yan avatar image Citrus Yan commented ·

Title id set in global/instance settings is different from the one set in the request, in order to make api calls, you must specify the title id in either global/instance settings, no matter whether the api request has a "titleid" field or not, so that it can be parsed and used to construct api endpoint urls.

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

May I know your code that produces the error mentioned above? Usually we call Client APIs with instance settings like the following:

PlayFabApiSettings instanceSettings = new PlayFabApiSettings()
            {
                TitleId = "xxxx"


            };
            var clientApiInstance = new PlayFabClientInstanceAPI(instanceSettings);
            var response = await clientApiInstance.LoginWithCustomIDAsync(new LoginWithCustomIDRequest()
            {
                CustomId = "xxxxxx",
            });
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.