question

Julien SEGERS avatar image
Julien SEGERS asked

Azure Functions: PlayFabServerAPI.GrantItemsToUserAsync customData parameter doesn't work?

Hello,

I'm using CloudScript on Azure Functions to grant an item to a player.

The item instance should have custom data associated with it. This custom data does not come from the catalog item custom data.

The user get the item in its inventory, but there is no custom data associated with it (for example, in this case it should be, Lvl = 5, HP = 50).

Thank you for your help!

Here is my function on Azure:

[FunctionName("GrantMonsterToUser")]
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            dynamic args = context.FunctionArgument;

            string itemId = args["id"];
            string lvl = args["lvl"];
            string hp = args ["hp"];
            List<string> itemIds = new List<string> { itemId };
            Dictionary<string, string> customData = new Dictionary<string, string> { 
                {"Lvl", lvl},
                {"HP", hp}
            };

            PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process);
            PlayFabSettings.staticSettings.TitleId = context.TitleAuthenticationContext.Id;
            
            var authContext = new PlayFabAuthenticationContext
            {
                EntityToken = context.TitleAuthenticationContext.EntityToken
            };

            var request = new GrantItemsToUserRequest
            {
                PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                AuthenticationContext = authContext,
                ItemIds = itemIds
            };

            return await PlayFabServerAPI.GrantItemsToUserAsync(request, customData);
        }
CloudScriptPlayer Inventory
10 |1200

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

Made Wang avatar image
Made Wang answered

This customData here does not belong to GrantItemsToUser. As said in this thread, this value is specific to the SDK. It's whatever data you want to tag onto the call, and then get back with the response, so that you know what call triggered it.

You can try to use GrantItemsToUsers, it can pass in Data while granting, here is its Request Body:

{
  "CatalogVersion": "{
                {PrimaryCatalogName}}",
  "ItemGrants": [
    {
      "PlayFabId": "{
                {PlayFabId}}",
      "ItemId": "shield_level_5",
      "Annotation": "Entered Level 5",
      "Data": {
        "Equipped": "True",
        "Slot": "Head"
      }
    }
  ]
}

The CustomTags in GrantItemsToUser is the tag of this request, which can be used for specific filtering, and it should be defined in the Request Body.

10 |1200

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

Made Wang avatar image
Made Wang answered

What needs to be clarified is that GrantItemsToUser cannotadd custom data, it can only add a behavior description in the Annotation of the Request Body. You can get the ItemInstanceId in the result of GrantItemsToUser, and then call UpdateUserInventoryItemCustomData to update the custom data.

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.

Julien SEGERS avatar image Julien SEGERS commented ·

Thank you for the answer.

I'm a bit confused though, is the "customData" parameter on GrantItemsToUserAsync a mistake? Maybe should it be named "customTags" instead?

Please see screenshot attached (sorry for the small size!).

Thank you!

0 Likes 0 ·
sans-titre.png (43.9 KiB)

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.