CREATE YOUR WORLD
Economy
Get information about items owned by a user
9min
you can use the zepeto module shop api to retrieve the item information of the currently connected user by category install window → package manager → please install zepeto world package 1 21 14 version or higher first then install the zepeto module package 1 0 7 version or higher zepeto module shop api if you're interested in the zepeto module shop api, refer to the documentation 📘 please refer to the following guide \[ zepeto module shop api https //developer zepeto me/docs/module/namespaces/zepeto module shop ] outputting item information example project > create > zepeto > typescript is created and the name is changed to myitemlist write a sample script as shown below import { zepetoscriptbehaviour } from 'zepeto script' import { shopservice, category, itemkeyword } from 'zepeto module shop' import { zepetopropertyflag } from 'zepeto' import { texture2d, waituntil } from 'unityengine' import { rawimage } from 'unityengine ui' import { item } from 'zepeto module content' export default class myitemlist extends zepetoscriptbehaviour { public thumbnailimage rawimage; start() { this startcoroutine(this cogetmycategory()); } cogetmycategory() { var requestcategory = shopservice getmycategoryasync(); yield new waituntil(() => requestcategory keepwaiting == false); if (requestcategory responsedata issuccess) { let categoryinfo = requestcategory responsedata category; console log(`\[category info] ${categoryinfo displayname} length ${categoryinfo categories length}`); let categories category\[] = categoryinfo categories; for (const category of categories) { console log(`\[category displayname] ${category displayname} `); //category keyword is used as an argument in the shopservice getmycontentitemlistasync function console log(`\[category keyword] ${category keyword} `); } } this startcoroutine(this cogetmyitem()); } cogetmyitem() { var requestitemlist = shopservice getmycontentitemlistasync(itemkeyword all, null); yield new waituntil(() => requestitemlist keepwaiting == false); if (requestitemlist responsedata issuccess) { let items item\[] = requestitemlist responsedata items; // the number of items received as a result of getmycontentitemlistasync() console log(items length); for (let i = 0; i < items length; ++i) { const property zepetopropertyflag = items\[i] property; // item id and item property console log(`\[content item] (id) ${items\[i] id} | (property) ${property}`); // setting the item thumbnail as the texture of a rawimage var texturereq = items\[i] getthumbnailasync(); yield new waituntil(() => texturereq keepwaiting == false); let thumbnailtexture texture2d = texturereq responsedata texture; this thumbnailimage texture = thumbnailtexture; } } } } script description retrieve my item tab information call shopservice getmycategoryasync() to know the item categories in the my item tab when you successfully receive a response, you can access the categoryresponse object through the responsedata property categoryresponse category categories is browsed and the item category list in the my item tab is outputted retrieve item list call shopservice getmycontentitemlistasync(itemkeyword all, null) to retrieve the item list for all categories you can choose to retrieve items from only certain categories for instance, you can use itemkeyword hair instead of itemkeyword all to retrieve only the hair items the second parameter is only used if you know the next page token to request set it to null the first time you call the api for examples related to nextpagetoken, check the information below when you receive a successful response, you can access the contentitemlistresponse object through the responsedata property itemresponse items is browsed and the id and the part enum code for each item is outputted also, the item thumbnail is set as the designated rawimage after you finish writing the script, add the script to the object in scene pressing the play button will show you the category list of the my item tab and the item information of all categories if you create the item thumbnail prefab and have the thumbnails to be created dynamically based on the item list, you can display the item list thumbnail on the ui example to check owned status of user's certain item you can utilize getmycontentitemlistasync() to check if someone on a world is wearing particular clothing the following is a simple example to display a message on the ui of a user who owns a specific item project > create > zepeto > typescript is created and the name is changed to checkitem write a sample script as shown below import { zepetoscriptbehaviour } from 'zepeto script' import { shopservice, itemkeyword } from 'zepeto module shop' import { zepetopropertyflag } from 'zepeto' import { waituntil } from 'unityengine' import { text } from 'unityengine ui' import { item } from 'zepeto module content' export default class checkitem extends zepetoscriptbehaviour { public resulttext text; public checkitemid string; start() { this resulttext gameobject setactive(false); this startcoroutine(this cocheckitem()); } cocheckitem() { let nextpagetoken string | null = null; do { // request the list of the user's content items const requestitemlist = shopservice getmycontentitemlistasync(itemkeyword all, nextpagetoken); yield new waituntil(() => requestitemlist keepwaiting == false); if (requestitemlist responsedata issuccess) { // get the content items from the response const contentitems item\[] = requestitemlist responsedata items; nextpagetoken = requestitemlist responsedata nextpagetoken; // iterate through the content items for (let i = 0; i < contentitems length; ++i) { const property zepetopropertyflag = contentitems\[i] property; // check if the item id matches the specified id if (contentitems\[i] id == this checkitemid) { // activate the matched item message this activatematcheditem(); break; } } } else { break; } } while (nextpagetoken != null); } activatematcheditem() { // show the matched item message this resulttext gameobject setactive(true); this resulttext text = "wow, you have an item i made!"; } } script description this is a script that browses the 'my item' list (all categories) of a user who is logged in to a world and finds the matching item id entered in the inspector if there are many items, the nextpagetoken value is not null therefore, the process is repeated with a do while statement until the value becomes null notice how nextpagetoken was provided as the second parameter of shopservice getmycontentitemlistasync(itemkeyword all, nextpagetoken) when you receive a successful response, you can access the contentitemlistresponse object through the responsedata property itemresponse items is browsed to find a match for the entered item id if a matching item is found, activatematcheditem() is called to display the text on the user's screen and end the loop after you finish writing the script, add the script to the object in scene enter the id of the item you wish to check if a user in a world has on the inspector press the play button to run the process text will appear on the screen if the user logged into a world has an item that matches the entered item id you can apply the example to create all sorts of interesting content