{"__v":3,"_id":"570ac955b044af0e0024f7b6","category":{"project":"56abbf55f25f160d00e17f4e","version":"56abbf55f25f160d00e17f51","_id":"570a5676ade45d0e00c1ad33","__v":0,"sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-04-10T13:34:46.864Z","from_sync":false,"order":3,"slug":"client-side-api","title":"Client Side API"},"parentDoc":null,"project":"56abbf55f25f160d00e17f4e","user":"56abbec30b9e0b0d00616274","version":{"__v":12,"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["58eba2762dd737230023dfd1"],"next":{"pages":[],"description":""},"createdAt":"2016-04-10T21:44:53.315Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":11,"body":"## Requesting User Item Instances\n\nThe inventory of any user can be requested by using the `requestUserItemList` method. This function takes a username string as the first argument, but you may pass in `null` or a blank string to request the inventory for the current user. The second argument is a callback function to call when retrieval is complete, which will generally involve a call to [use_item](doc:server-api-use-item) or [useItemInstance](doc:client-api-services-useiteminstance).\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`username`\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Username of the user to request items for, or `null` for the current user\",\n    \"1-0\": \"`callback`\",\n    \"1-1\": \"Function\",\n    \"1-2\": \"A callback function to be called with the results of the operation\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\nThe callback function is passed a single object with the following fields:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`success`\",\n    \"0-1\": \"Boolean\",\n    \"0-2\": \"A flag indicating whether or not the operation was successful\",\n    \"1-0\": \"`data`\",\n    \"1-1\": \"Array\",\n    \"1-2\": \"An array of item instances, if successful\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\nEach item definition in the `data` array contains the following fields:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`id`\",\n    \"0-1\": \"Integer\",\n    \"0-2\": \"The unique ID of the item instance\",\n    \"1-0\": \"`identifier`\",\n    \"1-1\": \"String\",\n    \"1-2\": \"The item identifier\",\n    \"2-0\": \"`data`\",\n    \"2-1\": \"String\",\n    \"2-2\": \"The metadata attached to the item instance, if any\",\n    \"3-0\": \"`remaining_uses`\",\n    \"3-1\": \"Integer\",\n    \"3-2\": \"Number of remaining uses, or 0 if this is an unlimited use item\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n**Example:** Request the inventory for the current player\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"kongregate.mtx.requestUserItemList(null, onUserItems);\\n\\nfunction onUserItems(result:Object):void {\\n  trace(\\\"User item list received, success: \\\" + result.success);\\n  if(result.success) {\\n    for(var i:int = 0; i < result.data.length; i++) {\\n      var item:Object = result.data[i];\\n      trace((i+1) + \\\". \\\" + item.identifier + \\\", \\\" + item.id + \\\",\\\" + item.data);\\n    }\\n  }\\n}\",\n      \"language\": \"haxe\",\n      \"name\": \"ActionScript 3\"\n    },\n    {\n      \"code\": \"kongregate.mtx.requestUserItemList(null, onUserItems);\\n\\nfunction onUserItems(result) {\\n  console.log(\\\"User item list received, success: \\\" + result.success);\\n  if(result.success) {\\n    for(var i=0; i < result.data.length; i++) {\\n      var item = result.data[i];\\n      console.log((i+1) + \\\". \\\" + item.identifier + \\\", \\\" + \\n                  item.id + \\\",\\\" + item.data);\\n    }\\n  }\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"Request a user's inventory from the server\n`requestUserItemList(username, callback)`","slug":"client-api-mtx-requestuseritemlist","type":"fn","title":"Mtx.RequestUserItemList"}

Mtx.RequestUserItemList

Request a user's inventory from the server `requestUserItemList(username, callback)`

## Requesting User Item Instances The inventory of any user can be requested by using the `requestUserItemList` method. This function takes a username string as the first argument, but you may pass in `null` or a blank string to request the inventory for the current user. The second argument is a callback function to call when retrieval is complete, which will generally involve a call to [use_item](doc:server-api-use-item) or [useItemInstance](doc:client-api-services-useiteminstance). [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "0-0": "`username`", "0-1": "String", "0-2": "Username of the user to request items for, or `null` for the current user", "1-0": "`callback`", "1-1": "Function", "1-2": "A callback function to be called with the results of the operation" }, "cols": 3, "rows": 2 } [/block] The callback function is passed a single object with the following fields: [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "0-0": "`success`", "0-1": "Boolean", "0-2": "A flag indicating whether or not the operation was successful", "1-0": "`data`", "1-1": "Array", "1-2": "An array of item instances, if successful" }, "cols": 3, "rows": 2 } [/block] Each item definition in the `data` array contains the following fields: [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "0-0": "`id`", "0-1": "Integer", "0-2": "The unique ID of the item instance", "1-0": "`identifier`", "1-1": "String", "1-2": "The item identifier", "2-0": "`data`", "2-1": "String", "2-2": "The metadata attached to the item instance, if any", "3-0": "`remaining_uses`", "3-1": "Integer", "3-2": "Number of remaining uses, or 0 if this is an unlimited use item" }, "cols": 3, "rows": 4 } [/block] **Example:** Request the inventory for the current player [block:code] { "codes": [ { "code": "kongregate.mtx.requestUserItemList(null, onUserItems);\n\nfunction onUserItems(result:Object):void {\n trace(\"User item list received, success: \" + result.success);\n if(result.success) {\n for(var i:int = 0; i < result.data.length; i++) {\n var item:Object = result.data[i];\n trace((i+1) + \". \" + item.identifier + \", \" + item.id + \",\" + item.data);\n }\n }\n}", "language": "haxe", "name": "ActionScript 3" }, { "code": "kongregate.mtx.requestUserItemList(null, onUserItems);\n\nfunction onUserItems(result) {\n console.log(\"User item list received, success: \" + result.success);\n if(result.success) {\n for(var i=0; i < result.data.length; i++) {\n var item = result.data[i];\n console.log((i+1) + \". \" + item.identifier + \", \" + \n item.id + \",\" + item.data);\n }\n }\n}", "language": "javascript" } ] } [/block]