Quickstart: Add your first item to a player’s inventory
Economy v2 is now Generally Available. For support and feedback, go to the PlayFab Forum.
Prerequisites
- A PlayFab developer account
- The PlayFab Beta SDK (You can find more information on the Postman Quickstart)
- At least one item in your catalog (You can find more information on the Economy v2 Quickstart)
- At least one player with sufficient virtual currency to purchase an item
Sign in as the player
You first need to sign in the player to receive the security token required for the remainder of the API calls in this quickstart. You can find more information on the Player Authentication page.Search for the item
To find the item in the catalog, callSearch. In the call body:
- The
Searchis the search string that is fuzzy searched against the Title, Description, and Keywords of every item in your catalog Topis an integer that determines how many results to return - in this case, we only need one
There are more fields you can learn about in the Search quickstart.
Items>Id- Catalog ID of the itemItems>PriceOptions>Prices>Amounts>ItemId- ID of the virtual currency used to purchase the itemItems>PriceOptions>Prices>Amounts>Amount- Amount of the virtual currency needed to purchase the item
Only Title Entities are able to set prices for Items.
Purchase the item
To purchase the item, callPurchaseInventoryItems. In the call body:
- The
Item.Idis the ID of the item (pulled from theSearchresponse in the previous step) - The
Amountis the number of items the player is purchasing - The
ItemIdis the ID of the virtual currency used to purchase the item (pulled from theSearchresponse in the previous step) - The
Amountis the amount of the virtual currency needed to purchase the item (pulled from theSearchresponse in the previous step)
Get the player’s inventory items
See the player’s newly purchased item viaGetInventoryItems. In the call, ensure the body is empty - you can specify the entity in the body, but isn’t necessary, as the information is already being passed in through the entity token in the header.
The response contains IDs of each item the player owns and the amount of each item. The newly purchased item is in the player’s inventory.
If the player already has that item in their inventory with the same
StackId, you won’t see another item instance after the purchase - instead, you’ll see the Amount field increase.Troubleshooting
- Insufficient funds
- If you call
PurchaseInventoryItemsand receive a422: InsufficientFundserror, the player doesn’t have enough virtual currency to purchase the item. You can grant virtual currency to the player by callingAddInventoryItems(requires title entity token) or navigating to [Title] > Players > [Player] >Inventory (V2)in Game Manager.
- If you call
- The item can’t be purchased at the specified price.
- If you call
PurchaseInventoryItemsand receive a1071error code, thePriceAmountsfield doesn’t match the prices specified in the catalog.
- If you call
Next steps
Now that you’ve purchased the player’s first item, you can consume the item, you can add the item to a store to put it on sale, and you can create and purchase a bundle containing the item.[!div class=“nextstepaction”] Player inventory tutorial
[!div class=“nextstepaction”] Stores
[!div class=“nextstepaction”] Bundles
