madmojoman avatar image
madmojoman asked

PlayFabServerAPI.GrantItemsToUser Multiple Items with Unique CustomData Inquiry

So, I have a situation where I need to setup specific CustomData for each individual item in a list of items to be granted to a user. When using the PlayFabServerAPI.GrantItemsToUser it only allows for a List<string> of ItemIDs to be used in the process for the actual GrantItemsToUserRequest, with an arbitrary "[object CustomData = null]" that can be used in the PlayFabServerAPI.GrantItemsToUser function, with a style of: PlayFabServerAPI.GrantItemsToUser(request, result, error, customData, extraHeaders)

I'm using a Unity custom game server project and attempting to create that CustomData object so that it will properly give in-order, specific and unique data to each of the inventory ItemInstances that are granted to the player, but I'm confused how the CustomData object attached to the GranItemsToUser function should be built to provide that functionality.

In my specific working situation at the moment, I was doing the GrantItemsToUser with a GrantItemsToUserRequest, and then sorting through the granted items looking for the ItemIDs that matched up with the unique data I needed to add to CustomData for each item. But, in some cases those ItemIDs aren't unique. For example; I will have two of ItemID:20001, which should have different CustomData from each other denoting a particular string value for a key. And then when I do the matching with ItemID it would result in two of the same inventory instances getting the same CustomData value, with one of the unique values not used at all.

Since the GrantItemsToUserResult.ItemResults does not guarantee returning those ItemInstances in the order in which they are positioned in the initial request array, what method can I use to request an item to be granted to a user's inventory from my server and set it's custom data at the same time, making certain that each inventory iteminstance receives it's proper, unique CustomData values upon successful granting of the item?

Can I use the PlayFabServerAPI.GrantItemsToUser that way? Should I just not send the list of ItemIds and include only the CustomData object (as an array of ItemGrants) in the PlayFabServerAPI.GrantItemsToUser(request, result, error, customData, extraHeaders) function? Or do I have to include both the list of ItemIds and the CustomData array of ItemGrants and hope they match them up in the proper order?

The documentation is not very clear on this point, and I can't seem to locate a C# reference to this particular situation.

I saw the forum post that is often referenced called Atomically Creating Items:

And it links to this part of the documentation:

Which only has a warning of: "Please note that the order of the items in the response may not match the order of items in the request." and does not actually explain how to request granting multiple items to a user with unique CustomData being set for each specific requested item in-order of request.

So, please, with sugar on top, can someone give me a concise example of a GranItemsToUser request that would include two of the same ItemIDs with two unique values being set for the same CustomData key, please? Example: ItemIDs to grant: 20001,20001, CustomData for first one: "UniqueIdentifier", "1", CustomData for second one: "UniqueIdentifier", "2". So that when successfully granted, I can look at the Inventory Instances granted and see that one has their CustomData key of "UniqueIdentifier" set to 1, and the other has it set to 2.

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.

madmojoman avatar image madmojoman commented ·

Is the problem that I've been using the "GrantItemsToUser" request instead of using the "GrantItemsToUsers" request? I have to target multiple users and then only direct the items to one user in order to use the ItemGrants array?

0 Likes 0 ·

1 Answer

madmojoman avatar image
madmojoman answered

Yes, the problem was that I needed to use the GrantItemsToUsers instead of GrantItemsToUser, and just setting up the ItemData for the ItemGrants with the info for each. I figured it out alright.

It'd be nice if there was an override for GrantItemsToUser (singular) that allowed for setting CustomData at the same time, as well. But I'm good now.

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.