question

drallcom3 avatar image
drallcom3 asked

Economy v2: AddInventoryItems doesn't work

AddInventoryItems doesn't work. I always get an InternalServerError 500.

I did allow clients to use that API.

The entity token is valid.

I also triple checked all IDs used.

Here are the different requests I tried (plus some other variations):

AddInventoryItemsRequest request = new AddInventoryItemsRequest
            {
                Entity = _entityTokenEconomy,
                Item = new InventoryItemReference
                {
                    Id = "92b6c344-636c-4e77-969c-6ca9cb7b7711", // Card item
                    StackId = "wellthisisntgreat"
                },
                Amount = 1
            };
AddInventoryItemsRequest request2 = new AddInventoryItemsRequest
            {
                Amount = 1,
                Entity = _entityTokenEconomy,
                Item = new InventoryItemReference
                {
                    Id = "bbd4905b-499b-440f-9de9-42f267751f82" // Gold currency
                }
            };
AddInventoryItemsRequest request3 = new AddInventoryItemsRequest
            {
                Amount = 1,
                Entity = _entityTokenEconomy,
                Item = new InventoryItemReference
                {
                    AlternateId = new AlternateId
                    {
                        Type = "FriendlyId",
                        Value = "gold" // Certainly no typo here
                    }
                }
            };
2 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.

drew avatar image drew commented ·

can you share the full Azure function? I'm struggling badly to get the AddInventoryItemsRequest to work

0 Likes 0 ·
drew avatar image drew commented ·

@drallcom3 can you share the full Azure function? I'm struggling badly to get the AddInventoryItemsRequest to work

0 Likes 0 ·
kylemc@microsoft.com avatar image
kylemc@microsoft.com answered

Yikes! Found the bug. Patching.

10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

In my test, the API call works fine. Can you use the code below to do some test?

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());
});
7 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 ·

I've tried your exact version. I also ran it with replacing your item ID.

They all result in:

/Inventory/AddInventoryItems: {"code":500,"status":"InternalServerError","data":{}}

My entity token is correct, since I run GetInventoryItems() with it before adding anything.

Enabling adding items for clients also works. I get a different error when I disable it.

Title 16F0F if you want to test.

Perhaps something is wrong with the item ID. I get the same error with a made-up ID that doesn't exist. I tried all sorts of things, chaning the amount, copy&pasting several IDs to rule out errors. It just won't work.

Edit: Interestingly PurchaseInventoryItems() works fine (on the first try!). That rules out several error on my part, like wrong IDs.

Edit2: SubtractInventoryItems() also works.

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

Is this issue still occurring for you? If so, can you provide a timestamp so we can look it up in the logs?

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

I tried again. Same error. Other people who are testing report the same error.

Timestamp: UTC Thursday, 22 September 2022, 13:23:00

Start there. It's a few seconds before or after.

I'll spam it a few more times.

0 Likes 0 ·
Show more comments
kylemc@microsoft.com avatar image kylemc@microsoft.com commented ·

The failure on SubtractInventoryItems is the standard "You don't have enough of the item/currency" failure. We're just not mapping it correctly outbound. We'll get a patch in for that.

0 Likes 0 ·
drallcom3 avatar image drallcom3 commented ·

Sorry, that was a Subtract. I had the Add commented out. Too much testing :)

Try

UTC Thursday, 22 September 2022, 17:36:00

There are several adds with error 500.

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.