question

drallcom3 avatar image
drallcom3 asked

Economy v2: How do I Add/Purchase an item?

How do I add/purchase an item in v2?

The documentation says to specify the desired item ID in the request body:

"Item": {
    "Id": "{
                {ItemID}}",
  }

Problem 1: The documentation of the API doesn't have the ID in the body.

Problem 2: The (Unity) SDK also doesn't have it.

Am I just blind or is it not possible to add/purchase items?

apissdks
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

·
Gosen Gao avatar image
Gosen Gao answered

You can specify the item Id with AddInventoryItems--InventoryItemReference/PurchaseInventoryItems--InventoryItemReference. To call those APIs, you can refer to the code below.

PlayFab.EconomyModels.EntityKey entity = new PlayFab.EconomyModels.EntityKey { Id = result.EntityToken.Entity.Id, Type = result.EntityToken.Entity.Type };
PlayFabEconomyAPI.AddInventoryItems(new PlayFab.EconomyModels.AddInventoryItemsRequest
{
    Amount = 1,
    Entity = entity,
    Item = new PlayFab.EconomyModels.InventoryItemReference
    {
        //AlternateId = new PlayFab.EconomyModels.AlternateId { Type = "FriendlyId", Value = "GSTS_item" },
        Id = "b9c6d241-67e4-4fd4-b459-c3cb2a462fcf",
        StackId = "TsStack1"
    }
},
result =>
{
    Debug.Log(result.IdempotencyId);
},
error =>
{
    Debug.Log(error.GenerateErrorReport());
});
5 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.

drallcom3 avatar image drallcom3 commented ·

InventoryItemReference was what confused me. It's not an InventoryItemReference, but a CatalogItemReference.

I recommend changing that name.

0 Likes 0 ·
danilo avatar image danilo commented ·

Can I use Bundle Id as an Id parameter within InventoryItemReference? For some reason I'm getting internal server error when I try to add bundle. Thanks

0 Likes 0 ·
kylemc@microsoft.com avatar image kylemc@microsoft.com danilo commented ·

Unfortunately, the preview Add API doesn't currently support bundles. We realized this would be a common request and have started the work to support this scenario.

1 Like 1 ·
acyace2020 avatar image acyace2020 kylemc@microsoft.com commented ·

Does the same applies to redeem <platform> purchases? (e.g., RedeemGooglePlayInventoryItems)

I've posted a problem but it's still waiting for moderation but I'm getting Internal Server Error as well for redeem with a bundle. If so, any workaround on it?

0 Likes 0 ·
Show more comments

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.