How to get InventoryItem definition from Economy?

I'm trying to get information stored in the custom data of an InventoryItem definition. I can't seem to find the call for it in CloudCode.

I'm looking for this call that's available in Unity:
InventoryItemDefinition definition = await EconomyService.Instance.Configuration.GetInventoryItemAsync(itemID);

I'm trying to do the exact same thing but haven't gotten a response yet (Would help if I posted in the correct forum lol) but I did find one posting that listed this:

const playerInventory = await inventoryApi.getPlayerInventory({ projectId, playerId, inventoryItemIds: itemSearch });

So it seems if you want to at least grab the specific item of an inventory you can get this. I still have no idea how you grab the instance data (which I really need for my project) but at least this seems like a step forward

I did some more digging and found this example on a response at nearly the end of the foums posted by one of the mods:

// Add new random reward TICKET to player's inventory
  const createdItem = await inventory.addInventoryItem(projectId, playerId,
   { inventoryItemId:"TICKET",
     instanceData: { "itemValue":itemValue,
                     "itemExpiresAt":itemExpiresAt }
   });
  const playersInventoryItemId = createdItem.data.playersInventoryItemId;
  logger.info("created Item : " + createdItem.data.playersInventoryItemId);

  const updatedItem = await inventory.updateInventoryItem(projectId, playerId, playersInventoryItemId,
    {
       instanceData: {
         "itemValue": 999
     }
   });

which looks like it might be used to solve both our needs!

I still haven’t gotten it to work yet, so if you do find how to make it work let me know :smile:

I think my case is a bit different from yours. I want to add an item to the player's inventory that they don't already have, so I can't get the item info from their inventory if it doesn't already exist.

The difference for my case is that I want to determine if the player is qualified to add the item based on the data that is stored on the item. For example, a SWORD requires a player to be level 20 for it to be added. Since I can't read the InventoryItem definitions, I can't know if the SWORD requires a level 20 or a level 50 players.

My current workaround is to store all item definitions on Remote Config. This is probably not the preferred way of doing this.

Oh gotcha! Yeah that does seem a bit more complicated. Remote Config sounds like it could work. Can you do something like add the item temporarily so you can check the data and remove if needed? Its a bit of a weird way to do it, but I suppose it would work.

I think that would incur a lot of extra read and writes to Economy (the most pricey to read/write) and also extra compute time on CloudCode to wait for responses. Remote Config is free (for now).

1 Like

Any luck on this from Cloud Code? I can't find anything about calling the equivalent to GetInventoryItemAsync() from Cloud code to get an InventoryItemDefinition-- all the API calls seem to get the player's inventory items which is not the same thing.

1 Like

I also want this solution and I haven’t found it yet. What I’m doing is this:
I search RemoteConfigs in a table that contains item IDs and minimum requirements.
Example: An Item Restriction table by Level.
Restriction of Items by Class.

Etc.
On the client side I call a cloudScript for purchasing, updating, and things I might want to do with items. At this point my script checks the remote configurations to see if there is a restriction and if so, it deals with it.

1 Like