Hello again developers, this topic is another tutorial about the Roblox API.
A few months ago I made one referring to the games, this time we’ll see the Inventory API
[Not to be confused with Catalog API]
Today well see:
- Detect if a player’s inventory is public
- Get assets [decal, model, etc] from a player’s inventory
- See owners of a limited item
- See if a player owns a specific item
Requires:
- It only works in game, not in studio so you’d better publish it before testing
- You need to have HTTP Request enabled and access to the API
Let’s start!
.
[Disclaimer]: You can only see a player’s inventory if its public to EVERYONE, which limits this quite a bit.
But to avoid errors, you better check if he has it visible or not
--Server
local HttpService = game:GetService("HttpService")
local CanSeeInventory = "https://inventory.roproxy.com/v1/users/"..player.UserId.."/can-view-inventory"
local Response = HttpService:RequestAsync({
Url = CanSeeInventory,
Method = "GET"
});
if Response.Success then -- If it doesnst work, then idk
local Body = HttpService:JSONDecode(Response.Body) -- Decoding the table
if Body.canView == true then
-- Continue Code
else
-- Do nothing, or warn the player
end
end
Question: Wait… how do you want me to get the player’s id if this script only works Server-Side???
Answer: RemoteEvents
.
Something important that I must clarify is that if you take a look at the Inventory API, it uses [inventory.roblox .com] and in this case Im replacing it with roproxy.
This is because Roblox doesnt allow access to its own API, so we use a proxy that accesses it without much modification.
.
Now I want to get the decals from a player’s inventory
As I said you can get models, decals, audios, etc.
-- Server
function GetDecals()
local Table = "https://inventory.roproxy.com/v2/users/"..player.UserId.."/inventory?assetTypes=Decal&limit=100&sortOrder=Asc"
local DecalResponse = HttpService:RequestAsync({
Url = Table,
Method = "GET"
});
if DecalResponse.Success then
local TableBody = HttpService:JSONDecode(DecalResponse.Body)
for i, v in pairs(TableBody) do
return v
end
end
end
-- The code below just prints it
local Decals = GetDecals()
if Decals ~= nil then -- Avoid errors
for i, v in pairs(Decals) do
print(v.name, v.assetId) -- Q: It wasnt "Name?" A: Not here
end
end
When you play with the API, you can see the properties:
In the first case
If I put v.assetId [decal id] it will return the number 6200961458
if I put v.name [decal name] will return the string “Moon Ground - QualityTextures”
Other cases
local Model = "https://inventory.roproxy.com/v2/users/"..player.UserId.."/inventory?assetTypes=Model&limit=100&sortOrder=Asc"
local Audio = "https://inventory.roproxy.com/v2/users/"..player.UserId.."/inventory?assetTypes=Audio&limit=100&sortOrder=Asc"
local Shirt = "https://inventory.roproxy.com/v2/users/"..player.UserId.."/inventory?assetTypes=Shirt&limit=100&sortOrder=Asc"
How can I see which people have a specific limited? why do you want that?
From what I saw, it only works in limiteds, and there are so many request that it produces that some user ids appear incorrect:
-- Server
function GetOwners(LimitedAsset)
local Table = "https://inventory.roproxy.com/v2/assets/"..LimitedAsset.."/owners?sortOrder=Asc&limit=10"
local Response = HttpService:RequestAsync({
Url = Table,
Method = "GET"
});
if Response.Success then
local TableBody = HttpService:JSONDecode(Response.Body)
for i, v in pairs(TableBody) do
return v
end
end
end
local LimitedAsset = 46348897
local Owners = GetOwners(LimitedAsset)
for i, v in pairs(Owners) do
print(v.id)
end
Scary Data
It was a sunny day, the orange luminescence of the sun illuminated my window, the leaves of the trees fell at the foot of my door while I was researching information for this topic
When viewing the API to see owners of a limited, you can take more than one screamer when copying user ids.
you have been warned
How to know if a player has a specific asset??
This may be used by most, but again, it will only work if the player’s inventory is public for everyone Any type of asset; models, decals or audios
Dont even think in gamepasses, they have their own function, no need to waste time
-- Server
local AssetId = 7795508934
local OwnedItem = "https://inventory.roproxy.com/v1/users/"..player.UserId.."/items/Asset/"..AssetId.."/is-owned"
local AssetResponse = HttpService:RequestAsync({
Url = OwnedItem,
Method = "GET"
});
if AssetResponse.Success then
local Body = HttpService:JSONDecode(AssetResponse.Body)
if Body == true then
-- Continue Code
end
end
The link to the Inventory API is here, there are other information tables there, but I think I gave the most important ones.