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 or useItemInstance.

Name

Type

Description

username

String

Username of the user to request items for, or null for the current user

callback

Function

A callback function to be called with the results of the operation

The callback function is passed a single object with the following fields:

Name

Type

Description

success

Boolean

A flag indicating whether or not the operation was successful

data

Array

An array of item instances, if successful

Each item definition in the data array contains the following fields:

Name

Type

Description

id

Integer

The unique ID of the item instance

identifier

String

The item identifier

data

String

The metadata attached to the item instance, if any

remaining_uses

Integer

Number of remaining uses, or 0 if this is an unlimited use item

Example: Request the inventory for the current player

kongregate.mtx.requestUserItemList(null, onUserItems);

function onUserItems(result:Object):void {
  trace("User item list received, success: " + result.success);
  if(result.success) {
    for(var i:int = 0; i < result.data.length; i++) {
      var item:Object = result.data[i];
      trace((i+1) + ". " + item.identifier + ", " + item.id + "," + item.data);
    }
  }
}
kongregate.mtx.requestUserItemList(null, onUserItems);

function onUserItems(result) {
  console.log("User item list received, success: " + result.success);
  if(result.success) {
    for(var i=0; i < result.data.length; i++) {
      var item = result.data[i];
      console.log((i+1) + ". " + item.identifier + ", " + 
                  item.id + "," + item.data);
    }
  }
}