question

matt-3 avatar image
matt-3 asked

Grant Item in Unity

I am trying to grant an item to a user (non- purchase) in a Unity3D game. I see the GrantItemsToUsers in the docs but I dont see it in the API.

Is this possible? If not, what is the best way to give a user an inventory item?

In-Game Economy
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

·
brendan avatar image
brendan answered

There are two possible API calls you may be looking for:

https://api.playfab.com/documentation/server/method/GrantItemsToUser

https://api.playfab.com/documentation/server/method/GrantItemsToUsers

Can you check to make sure you've enabled the Server API in your project?

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.

matt-3 avatar image matt-3 commented ·

@Brendan Thanks, I added the Server API and now can see the Grant item code. However, I am getting an invalid parameter when using this Unity code:

publicvoidGrantItem(string itemType)
{
varrequest=newGrantItemsToUsersRequest();
request.ItemGrants=newList<ItemGrant>();
request.ItemGrants.Add(newItemGrant{PlayFabId = UserInfo.PlayerData.id});
request.ItemGrants.Add(newItemGrant{ItemId =itemType});

PlayFabServerAPI.GrantItemsToUsers(request,LogSuccess,LogFailure);
}

Am I not building the list correct?

0 Likes 0 ·
brendan avatar image brendan matt-3 commented ·

In that code, it looks like you're adding an ItemGrant with the PlayFab ID, and separately adding another with the Item ID set. Each ItemGrant needs to have both set - can you give that a try?

0 Likes 0 ·
matt-3 avatar image matt-3 commented ·

I see. I got it all working now. 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.