InventoryService

From OpenSimulator

Revision as of 11:52, 4 December 2014 by Justincc (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Introduction

The OpenSimulator inventory service stores user inventory data (object items, notecard items, folders, etc.) and provides this on request. Note that every inventory item points towards an immutable asset entry that actually contains the data.

The current default ROBUST OpenSimulator inventory service is known as the XInventoryService.

TODO: Document remaining operations: CREATEUSERINVENTORY (unused), GETUSERINVENTORY (unused), GETINVENTORYSKELETON, GETROOTFOLDER, UPDATEFOLDER, MOVEFOLDER, DELETEFOLDERS, PURGEFOLDER, UPDATEITEM, MOVEITEMS, GETACTIVEGESTURES, GETASSETPERMISSIONS.

API

General notes

Unlike the asset service, the xinventory service is an RPC interface. Therefore it exposes only one URI which is xinventory (e.g. http://localhost:8003/xinventory). The invocation of different operations (e.g. add item, get item) is controlled via a METHOD parameter.

Formats

The API calls below return folder and item data in the same format. These formats are detailed below.

Item

This has the form

<item type="List">
  <AssetID>31f51766-4a99-4b59-9e53-61f436614c71</AssetID>
  <AssetType>6</AssetType>
  <BasePermissions>581639</BasePermissions>
  <CreationDate>1347487471</CreationDate>
  <CreatorId>efc1b932-20e3-4298-8824-0f891fe3dc59</CreatorId>
  <CreatorData/>
  <CurrentPermissions>581639</CurrentPermissions>
  <Description/>
  <EveryOnePermissions>0</EveryOnePermissions>
  <Flags>0</Flags>
  <Folder>859723cf-6338-497b-ab70-64ca04b64f70</Folder>
  <GroupID>00000000-0000-0000-0000-000000000000</GroupID>
  <GroupOwned>False</GroupOwned>
  <GroupPermissions>0</GroupPermissions>
  <ID>25e16367-accd-4b92-8f46-b55d3f63ad0d</ID>
  <InvType>6</InvType>
  <Name>Primitive</Name>
  <NextPermissions>581632</NextPermissions>
  <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
  <SalePrice>0</SalePrice>
  <SaleType>0</SaleType>
</item>

where

  • AssetID is the UUID of the asset for this inventory item (e.g. the actual serialized object data for a primitive).
  • AssetType is the asset type of this item. See the AssetType enum in libopenmetaverse for more details. In this case the asset type is 6 to denote an object.
  • BasePermissions the base permissions for the item. See the Permissions flags enum in libopenmetaverse for more details.
  • CreationDate is the unix time stamp of the creation date of the item.
  • CreatorId is the UUID of the creator.
  • CreatorData is extended creator data information for the item (as used by the --creators option in the "save iar" command). This may be blank.
  • CurrentPermissions are the permissions that the current owner has over the item when rezzed. See the Permissions flags enum in libopenmetaverse for more details.
  • Description is the description of the item. This may be blank.
  • EveryOnePermissions are the permissions that anyone would have over the item when rezzed. See the Permissions flags enum in libopenmetaverse for more details.
  • Flags is an integer flags entry. For a bodypart or clothing (both wearables), the type of wearable is signalled by an enumeration. See the WearableType enum in libopenmetaverse for more details. In this case, the value is zero since we're dealing with an object rather than a wearable. Other possible uses of Flags need documentation.
  • Folder is the UUID of the folder containing this item.
  • GroupID is the UUID of the group that owns this item, if any. If there is no owner then this is UUID.Zero (00000000-0000-0000-0000-000000000000).
  • GroupOwner is true if the item is group owned, false if not.
  • GroupPermissions are the group permissions for the item, if applicable. See the Permissions flags enum in libopenmetaverse for more details.
  • ID is the UUID of the item.
  • InvType is the inventory type of the item. See the InventoryType enum in libopenmetaverse for more details. In this case the inventory type is 6 to denote an object.
  • Name is the name of the item.
  • NextPermissions are the permissions that the next owner of this item will receive.
  • Owner is the UUID of the owner of this item
  • SalePrice is the sale price of this item.
  • SaleType is the sale type of this item. See the SaleType enum in libopenmetaverse for more details.

In some cases where multiple items can be returned the item element will have an underscore and index value appended (e.g. item_0 instead of folder). This is for historical reasons.

Folder

This has the form

<folder type="List">
  <ParentID>00000000-0000-0000-0000-000000000000</ParentID>
  <Type>9</Type>
  <Version>1</Version>
  <Name>My Inventory</Name>
  <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
  <ID>035f457b-a0f6-4580-a10c-e4f908e176ac</ID>
</folder>

where

  • ParentID is the parent folder ID. For the root ("My Inventory") folder this is always UUID.Zero (00000000-0000-0000-0000-000000000000).
  • Type is the type of the folder. See the InventoryType enum in libopenmetaverse for more details. In this case, the type is 9 (RootCategory) since this is a root folder.
  • Version is the version of the folder. This is used for viewer inventory caching purposes.
  • Name is the name of the folder.
  • Owner is the UUID of the avatar that owns the folder.
  • ID is the unique id of the folder itself.

In some cases where multiple folders can be returned the folder element will have an underscore and index value appended (e.g. folder_0 instead of folder). This is for historical reasons.

Calls

GETROOTFOLDER

This returns data about a user's root folder (i.e. their "My Inventory" folder). POST field is a urlencoded string like so

PRINCIPAL=efc1b932-20e3-4298-8824-0f891fe3dc59&METHOD=GETROOTFOLDER

where

  • METHOD is GETROOTFOLDER
  • PRINCIPAL is the UUID of the user

If successful, example return is

<?xml version="1.0"?>
<ServerResponse>
  <folder type="List">
    <ParentID>00000000-0000-0000-0000-000000000000</ParentID>
    <Type>9</Type>
    <Version>1</Version>
    <Name>My Inventory</Name>
    <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
    <ID>035f457b-a0f6-4580-a10c-e4f908e176ac</ID>
  </folder>
</ServerResponse>

If the request fails (e.g. because the PRINCIPAL does not exist) you will receive an empty response

<?xml version="1.0"?><ServerResponse />

See #Folder for more details about the folder format.

Sample scripts

<?php
 
    $ch = curl_init("http://localhost:8003/xinventory");
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "PRINCIPAL=efc1b931-20e3-4298-8824-0f891fe3dc59&METHOD=GETROOTFOLDER");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "$result\n";
 
?>

GETFOLDERFORTYPE

This returns data about the user's system folder for a particular type (e.g. their "Clothing" system folder). POST field is a urlencoded string like so

PRINCIPAL=efc1b932-20e3-4298-8824-0f891fe3dc59&TYPE=13&METHOD=GETFOLDERFORTYPE

where

  • METHOD is GETFOLDERFORTYPE
  • PRINCIPAL is the UUID of the user
  • TYPE is the type of system folder to get. See the AssetType enum in libopenmetaverse for more details. In this case the asset type is 13 for the body parts sytem folder.

If successful, example return is

<?xml version="1.0"?>
<ServerResponse>
  <folder type="List">
    <ParentID>035f457b-a0f6-4580-a10c-e4f908e176ac</ParentID>
    <Type>13</Type>
    <Version>5</Version>
    <Name>Body Parts</Name>
    <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
    <ID>40506578-704d-49bb-adbc-98b2c4719fb2</ID>
  </folder>
</ServerResponse>

If the request fails (e.g. because the PRINCIPAL does not exist or a system folder of the given type does not exist) you will receive an empty response with an HTTP OK status code.

<?xml version="1.0"?><ServerResponse />

See #Folder for more details about the folder format.

Sample scripts

<?php
 
    $ch = curl_init("http://localhost:8003/xinventory");
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "PRINCIPAL=efc1b931-20e3-4298-8824-0f891fe3dc59&TYPE=13&METHOD=GETFOLDERFORTYPE");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "$result\n";
 
?>

GETFOLDER

This returns data about a particular inventory folder. POST field is a urlencoded string like so

ID=efc1b932-20e3-4298-8824-0f891fe3dc59&METHOD=GETFOLDER

where

  • METHOD is GETFOLDER
  • ID is the folder UUID

If successful, example return is

<?xml version="1.0"?>
<ServerResponse>
  <folder type="List">
    <ParentID>035f457b-a0f6-4580-a10c-e4f908e176ac</ParentID>
    <Type>8</Type>
    <Version>1</Version>
    <Name>Some folder</Name>
    <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
    <ID>e3c2a5e8-20c4-4e70-a994-61dae3265b58</ID>
  </folder>
</ServerResponse>

If the request fails (e.g. because the PRINCIPAL does not exist) you will receive an empty response

<?xml version="1.0"?><ServerResponse />

See #Folder for more details about the folder format.

Sample scripts

<?php
 
    $ch = curl_init("http://localhost:8003/xinventory");
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "ID=e3c2a5e8-20c4-4e70-a994-61dae3265b58&METHOD=GETFOLDER");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "$result\n";
 
?>

GETFOLDERCONTENT

This returns the children folders and items of a given inventory folder. POST field is a urlencoded string like so

PRINCIPAL=efc1b931-20e3-4298-8824-0f891fe3dc59&FOLDER=efc1b932-20e3-4298-8824-0f891fe3dc59&METHOD=GETFOLDERCONTENT

where

  • METHOD is GETFOLDERCONTENT
  • PRINCIPAL is the user that owns the folder. This is currently mandatory but is really only present for historical reasons.
  • FOLDER is the folder UUID

If successful, example return is

<?xml version="1.0"?>
<ServerResponse>
  <FOLDERS type="List">
    <folder_0 type="List">
      <ParentID>859723cf-6338-497b-ab70-64ca04b64f70</ParentID>
      <Type>-1</Type>
      <Version>1</Version>
      <Name>f1</Name>
      <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
      <ID>4174f4cd-9ff5-8d23-0721-2a758f36f7d0</ID>
    </folder_0>
  </FOLDERS>
  <ITEMS type="List">
    <item_0 type="List">
      <AssetID>31f51766-4a99-4b59-9e53-61f436614c71</AssetID>
      <AssetType>6</AssetType>
      <BasePermissions>581639</BasePermissions>
      <CreationDate>1347487471</CreationDate>
      <CreatorId>efc1b932-20e3-4298-8824-0f891fe3dc59</CreatorId>
      <CreatorData/>
      <CurrentPermissions>581639</CurrentPermissions>
      <Description/>
      <EveryOnePermissions>0</EveryOnePermissions>
      <Flags>0</Flags>
      <Folder>859723cf-6338-497b-ab70-64ca04b64f70</Folder>
      <GroupID>00000000-0000-0000-0000-000000000000</GroupID>
      <GroupOwned>False</GroupOwned>
      <GroupPermissions>0</GroupPermissions>
      <ID>25e16367-accd-4b92-8f46-b55d3f63ad0d</ID>
      <InvType>6</InvType>
      <Name>Primitive</Name>
      <NextPermissions>581632</NextPermissions>
      <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
      <SalePrice>0</SalePrice>
      <SaleType>0</SaleType>
    </item_0>
    <item_1 type="List">
      <AssetID>37f0cbe1-c61f-492b-835b-f9f44b636e37</AssetID>
      <AssetType>6</AssetType>
      <BasePermissions>581633</BasePermissions>
      <CreationDate>1347400903</CreationDate>
      <CreatorId>efc1b932-20e3-4298-8824-0f891fe3dc59</CreatorId>
      <CreatorData/>
      <CurrentPermissions>581633</CurrentPermissions>
      <Description/>
      <EveryOnePermissions>0</EveryOnePermissions>
      <Flags>0</Flags>
      <Folder>859723cf-6338-497b-ab70-64ca04b64f70</Folder>
      <GroupID>00000000-0000-0000-0000-000000000000</GroupID>
      <GroupOwned>False</GroupOwned>
      <GroupPermissions>0</GroupPermissions>
      <ID>dde22b2c-1ae3-40df-8480-7b793544aceb</ID>
      <InvType>6</InvType>
      <Name>Primitive2</Name>
      <NextPermissions>581632</NextPermissions>
      <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
      <SalePrice>0</SalePrice>
      <SaleType>0</SaleType>
    </item_1>
  </ITEMS>
</ServerResponse>

If the request fails (e.g. because the PRINCIPAL does not exist) you will receive an empty response

<?xml version="1.0"?><ServerResponse />

See #Folder for more details about the folder format. Note that the folder elements here have an index parameter appended (<folder_0> rather than <folder>). This piece of insanity is for historical reasons.

See #Item for more details about the item format. Note that the item elements here have an index parameter appended (<item_0> rather than <item>). This piece of insanity is for historical reasons.

Sample scripts

<?php
 
    $ch = curl_init("http://localhost:8003/xinventory");
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "PRINCIPAL=efc1b931-20e3-4298-8824-0f891fe3dc59&FOLDER=e3c2a5e8-20c4-4e70-a994-61dae3265b58&METHOD=GETFOLDERCONTENT");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "$result\n";
 
?>

GETFOLDERITEMS

This returns the items of a given inventory folder. POST field is a urlencoded string like so

PRINCIPAL=efc1b931-20e3-4298-8824-0f891fe3dc59&FOLDER=efc1b932-20e3-4298-8824-0f891fe3dc59&METHOD=GETFOLDERITEMS

where

  • METHOD is GETFOLDERCONTENT
  • PRINCIPAL is the user that owns the folder. This is currently mandatory but is really only present for historical reasons.
  • FOLDER is the folder UUID

If successful, example return is

<?xml version="1.0"?>
<ServerResponse>
  <ITEMS type="List">
    <item_0 type="List">
      <AssetID>31f51766-4a99-4b59-9e53-61f436614c71</AssetID>
      <AssetType>6</AssetType>
      <BasePermissions>581639</BasePermissions>
      <CreationDate>1347487471</CreationDate>
      <CreatorId>efc1b932-20e3-4298-8824-0f891fe3dc59</CreatorId>
      <CreatorData/>
      <CurrentPermissions>581639</CurrentPermissions>
      <Description/>
      <EveryOnePermissions>0</EveryOnePermissions>
      <Flags>0</Flags>
      <Folder>859723cf-6338-497b-ab70-64ca04b64f70</Folder>
      <GroupID>00000000-0000-0000-0000-000000000000</GroupID>
      <GroupOwned>False</GroupOwned>
      <GroupPermissions>0</GroupPermissions>
      <ID>25e16367-accd-4b92-8f46-b55d3f63ad0d</ID>
      <InvType>6</InvType>
      <Name>Primitive</Name>
      <NextPermissions>581632</NextPermissions>
      <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
      <SalePrice>0</SalePrice>
      <SaleType>0</SaleType>
    </item_0>
    <item_1 type="List">
      <AssetID>37f0cbe1-c61f-492b-835b-f9f44b636e37</AssetID>
      <AssetType>6</AssetType>
      <BasePermissions>581633</BasePermissions>
      <CreationDate>1347400903</CreationDate>
      <CreatorId>efc1b932-20e3-4298-8824-0f891fe3dc59</CreatorId>
      <CreatorData/>
      <CurrentPermissions>581633</CurrentPermissions>
      <Description/>
      <EveryOnePermissions>0</EveryOnePermissions>
      <Flags>0</Flags>
      <Folder>859723cf-6338-497b-ab70-64ca04b64f70</Folder>
      <GroupID>00000000-0000-0000-0000-000000000000</GroupID>
      <GroupOwned>False</GroupOwned>
      <GroupPermissions>0</GroupPermissions>
      <ID>dde22b2c-1ae3-40df-8480-7b793544aceb</ID>
      <InvType>6</InvType>
      <Name>Primitive2</Name>
      <NextPermissions>581632</NextPermissions>
      <Owner>efc1b932-20e3-4298-8824-0f891fe3dc59</Owner>
      <SalePrice>0</SalePrice>
      <SaleType>0</SaleType>
    </item_1>
  </ITEMS>
</ServerResponse>

If the request fails (e.g. because the PRINCIPAL does not exist) you will receive an empty response

<?xml version="1.0"?><ServerResponse />

See #Item for more details about the item format. Note that the item elements here have an index parameter appended (<item_0> rather than <item>). This piece of insanity is for historical reasons.

Sample scripts

<?php
 
    $ch = curl_init("http://localhost:8003/xinventory");
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "PRINCIPAL=efc1b931-20e3-4298-8824-0f891fe3dc59&FOLDER=e3c2a5e8-20c4-4e70-a994-61dae3265b58&METHOD=GETFOLDERITEMS");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "$result\n";
 
?>

GETITEM

This returns data about a particular inventory item. POST field is a urlencoded string like so

ID=2b410a2f-e639-4d09-a4d4-e6ca71bc68bd&METHOD=GETITEM

where

  • METHOD is GETITEM
  • ID is the item UUID

If successful, example return is

<?xml version="1.0"?>
<ServerResponse>
  <item type="List">
    <AssetID>8ecbd3a0-dd45-44e7-91f8-114a67f0d5c3</AssetID>
    <AssetType>6</AssetType>
    <BasePermissions>581633</BasePermissions>
    <CreationDate>1351634945</CreationDate>
    <CreatorId>e4f3924a-5a7c-4e1a-bee7-aa96580f2515</CreatorId>
    <CreatorData/>
    <CurrentPermissions>581633</CurrentPermissions>
    <Description/>
    <EveryOnePermissions>0</EveryOnePermissions>
    <Flags>0</Flags>
    <Folder>41e05ba4-fbdc-48f8-854b-29d8409884e6</Folder>
    <GroupID>00000000-0000-0000-0000-000000000000</GroupID>
    <GroupOwned>False</GroupOwned>
    <GroupPermissions>0</GroupPermissions>
    <ID>2b410a2f-e639-4d09-a4d4-e6ca71bc68bd</ID>
    <InvType>6</InvType>
    <Name>Primitive</Name>
    <NextPermissions>581632</NextPermissions>
    <Owner>e4f3924a-5a7c-4e1a-bee7-aa96580f2515</Owner>
    <SalePrice>0</SalePrice>
    <SaleType>0</SaleType>
  </item>
</ServerResponse>

If the request fails then you will see a blank service response

<?xml version="1.0"?>
<ServerResponse/>

ADDFOLDER

This adds an folder to a user's inventory. POST field is a urlencoded string like so

Name=Current+Outfit&ID=F5BF95EB-DE03-808D-E98E-DDDBC8F3CB2E&ParentID=0592938c-ee24-45a5-af04-55e0f30838f7&Owner=efc1b932-20e3-4298-8824-0f891fe3dc59&Type=46&Version=1&METHOD=ADDFOLDER

The format of the elements of these params is the same as in #Folder. The folder version should always be 1. This example actually adds a "Current Outfit" type folder - normally the type would be 8 (for an ordinary folder).

If successful, return is

<?xml version="1.0"?>
<ServerResponse>
  <RESULT>True</RESULT>
</ServerResponse>

If unsuccessful then

<?xml version="1.0"?>
<ServerResponse>
  <RESULT>False</RESULT>
</ServerResponse>

Sample scripts

<?php
 
function PostInventoryOp($serviceUri, $postFields)
{
    echo "postFields:$postFields\n";
 
    $ch = curl_init($serviceUri);
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "Return data: (below)\n" . GetPrettyXML($result) . "\n";
 
    return new SimpleXmlElement($result);    
}
 
function AddFolder($serviceUri, $folderName, $folderId, $parentFolderId, $userId, $assetType)
{
    $params 
        = array(
            'Name' => $folderName,
            'ID' => $folderId,
            'ParentID' => $parentFolderId,
            'Owner' => $userId,
            'Type' => $assetType,
            'Version' => 1,
            'METHOD' => "ADDFOLDER");
 
    return PostInventoryOp($serviceUri, http_build_query($params), TRUE);            
}
 
$inventoryServiceUri = "http://localhost:8003/xinventory";
$USER_ID = "efc1b932-20e3-4298-8824-0f891fe3dc59";
 
AddFolder(
    $inventoryServiceUri, 
    "Current Outfit", 
    "F5BF95EB-DE03-808D-E98E-DDDBC8F3CB2E", 
    "0592938c-ee24-45a5-af04-55e0f30838f7", 
    $USER_ID, 
    46);
 
?>

ADDITEM

This adds an inventoryitem to a given inventory folder. POST field is a urlencoded string like so

AssetID=4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7&AssetType=13&Name=my+eyes+2&Owner=efc1b932-20e3-4298-8824-0f891fe3dc59&ID=7C8A732C-9634-3800-AB97-DD2EF4C1B367&InvType=18&CreatorId=efc1b932-20e3-4298-8824-0f891fe3dc59&CreatorData=&Description=generic+eyes+desc&BasePermissions=581639&CurrentPermissions=581632&NextPermissions=581639&EveryOnePermissions=0&GroupID=00000000-0000-0000-0000-000000000000&GroupOwned=False&GroupPermissions=0&SalePrice=0&SaleType=0&Flags=3&CreationDate=1347571855&Folder=40506578-704d-49bb-adbc-98b2c4719fb2&METHOD=ADDITEM

The format of the elements of these params is the same as in #Item

If successful, return is

<?xml version="1.0"?>
<ServerResponse>
  <RESULT>True</RESULT>
</ServerResponse>

If unsuccessful then

<?xml version="1.0"?>
<ServerResponse>
  <RESULT>False</RESULT>
</ServerResponse>

Sample scripts

<?php
 
function PostInventoryOp($serviceUri, $postFields)
{
    echo "postFields:$postFields\n";
 
    $ch = curl_init($serviceUri);
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "Return data: (below)\n" . GetPrettyXML($result) . "\n";
 
    return new SimpleXmlElement($result);    
}
 
function AddInventoryItem(
    $serviceUri, $itemName, $itemDescription, $assetType, $itemType, $wearableType, $assetId, $userId, $folderId)
{
    $addInventoryParams 
        = array(
            'AssetID' => $assetId,
            'AssetType' => $assetType,
            'Name' => $itemName,
            'Owner' => $userId,
            'ID' => GenerateUuid(),
            'InvType' => $itemType,            
            'CreatorId' => $userId,
            'CreatorData' => "",
            'Description' => $itemDescription,
            'BasePermissions' => 581639,
            'CurrentPermissions' => 581632,            
            'NextPermissions' => 581639,
            'EveryOnePermissions' => 0,
            'GroupID' => "00000000-0000-0000-0000-000000000000",
            'GroupOwned' => "False",
            'GroupPermissions' => 0,
            'SalePrice' => 0,
            'SaleType' => 0,
            'Flags' => $wearableType,
            'CreationDate' => time(),
            'Folder' => $folderId,
            'METHOD' => "ADDITEM");                                 
 
    return PostInventoryOp($serviceUri, http_build_query($addInventoryParams));
}
 
function GetFolderForType($serviceUri, $principalId, $type)
{
    $typeParams = array('PRINCIPAL' => $principalId, 'TYPE' => $type, 'METHOD' => "GETFOLDERFORTYPE");
    $responseE = PostInventoryOp($serviceUri, http_build_query($typeParams));
    return $responseE->folder;    
}
 
$inventoryServiceUri = "http://localhost:8003/xinventory";
$USER_ID = "efc1b932-20e3-4298-8824-0f891fe3dc59";
 
$bodypartFolderTypeE = GetFolderForType($inventoryServiceUri, $USER_ID, 13);
 
// eyes
AddInventoryItem(
    $inventoryServiceUri, 
    "my eyes 2", 
    "generic eyes desc", 
    13, 
    18,
    3, 
    "4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7",
    $USER_ID, 
    (string)$bodypartFolderTypeE->ID);  
 
?>

DELETEITEMS

These deletes inventory items for a given user. POST field is a urlencoded string like so

METHOD=DELETEITEMS&PRINCIPAL=efc1b932-20e3-4298-8824-0f891fe3dc59&ITEMS[]=1d09e24c-2b2a-8072-602a-950c9a3a8d18&ITEMS[]=3a057d48-adc7-de32-060f-0aac62fc6da9

where

  • METHOD is the API method, in this case DELETEITEMS
  • PRINCIPAL is the user UUID.
  • ITEMS[] are the UUIDs of the items to delete. There can be one or many of these.

Response is currently always

<?xml version="1.0"?>
<ServerResponse>
  <RESULT>True</RESULT>
</ServerResponse>

even if the given principal or item IDs are not found or are not well-formed UUIDs.

<?xml version="1.0"?>
<ServerResponse>
  <RESULT>False</RESULT>
</ServerResponse>

will only be returned if the PRINCPIAL parameter or any ITEMS[] parameters were not present.

Sample scripts

<?php
 
function PostInventoryOp($serviceUri, $postFields)
{
    echo "postFields:$postFields\n";
 
    $ch = curl_init($serviceUri);
 
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
 
    echo "Return code:" . $info['http_code'] . "\n";
    echo "Return data: (below)\n" . GetPrettyXML($result) . "\n";
 
    return new SimpleXmlElement($result);    
}
 
function DeleteInventoryItems($serviceUri, $principalId, $itemIds)
{
    $params = "METHOD=DELETEITEMS&PRINCIPAL=$principalId";
 
    foreach ($itemIds as $itemId)
    {
        $params .= "&ITEMS[]=$itemId";
    }
 
    return PostInventoryOp($serviceUri, $params);                                  
}
?>
Personal tools
General
About This Wiki