How to get the latest asset id

hello again
So, I was just curious, how would I get the latest asset id?

For example, lets say a Hat, was created just now, like right now, and then another hat which came after it, I want to get the latest item created asset id. Is that possible?

Is there any way you can get into more detail so I understand better? Thank you!

Okay.

Lets say I made a asset, a block. put it for sale, and its the latest asset, and it has this id right? Now i want to get its id, thats all

Hmmmm
I think you have to press that block on the website
Then in the URL, take the numbers, copy them
I think that is it
Tell me if there are errors

Thats not what i asked,
like, lets say i submit a model to toolbox, I just created it now, so the script will say the latest model id is the model i just submitted to toolbox

If you have a proxy what you can do is.
Avatar shop: https://catalog.roblox.com/v1/search/items?category=All&limit=120&sortType=3
Creator Marketplace (Models, Audios, etc) pretty sure is not possible as their endpoints return HTML and not JSON

This can be inconvenient because of it being the recently updated assets. Unfortunately, I don’t think Roblox will ever have a sorting feature as such. But hey, I guess you can still make a game like New User Machine :joy:

Not to mention this.

This only works on google

Do you know how the “Pls Donate” games operate? They use a proxy to make API requests, getting the necessary data they need.

You would have to do the same here - probably in a loop with a bunch of seconds cooldown, keep checking the account’s models and keep the newest version on a variable. Then, whenever you get a new one, just compare with that old one and if it finds acceptable differences, look for the value in the new one that does not exist in the old.

Congrats, you got the ID!

alr here we go. We use something the chads call “Roblox Catalog Api.” Unfortunately, we aren’t chads, so we must follow what the chads do in order to become a chad.

Here is the process of what we’ll do.

  1. send request to catalog api to get the recently updated items
  2. get the latest item from that response array
  3. check if creation date was today, if so, we found the latest item.

First, create a script in ServerScriptService called “GetLatestAsset.”

Lets setup our functions.

local HttpService = game:GetService("HttpService") -- enable httpservice by doing game.HttpService.HttpEnabled = true inside command prompt

local function getLatestAsset()
	
end

while true do
	getLatestAsset()
	task.wait(10)
end

now, lets set up our getLatestAsset function. Lets first send a request to https://catalog.roblox.com/v1/search/items?category=Accessories&limit=120&sortType=3&subcategory=Accessories and get the recently updated items. We will need to use a proxy like roproxy.com

local HttpService = game:GetService("HttpService") -- enable httpservice by doing game.HttpService.HttpEnabled = true inside command prompt

local function getLatestAsset()
	
	local success, assetId = pcall(function()
		local latestAssetId 
		
		local assetsResponse = HttpService:RequestAsync({
			Url = "https://catalog.roproxy.com/v1/search/items?category=Accessories&limit=120&sortType=3&subcategory=Accessories", -- the url
		})
		local assetsBody = HttpService:JSONDecode(assetsResponse.Body) -- get the body from our response(the body is the data that was returned)
		
		
		-- next we need to see if you request to roblox api failed, 
		-- if so, we throw an error which will be catched by our catch block
		
		if not assetsResponse.Success then
			error(string.format("%s %s", assetsResponse.StatusCode, assetsResponse.StatusMessage)) -- throw an error with the status code and status message
		end
		
		latestAssetId = assetsBody.data[1].id
		return latestAssetId -- return latest assetId
	end)
	
	if not success then
		warn(string.format("Failed to get latest asset because: %s", assetId)) -- send a warning in the output to tell u request failed
	else 
		print(string.format("Got latest asset B) asset id: %d", assetId)) -- print latest asset id
	end		
end

while true do
	getLatestAsset()
	task.wait(10)
end

now this works, but there’s an issue.

Lets say roblox updates a hat, well then the hat will be boosted to the top of the recently updated category. Fix? Well, it’s simple, we get the creation date and updated date and see if they have they were updated and created on the same day, if they dont, that’ll mean the hat was updated. We can do this via MarketPlaceService:GetProductInfo. If you are doing this outside of roblox, idk what endpoint you use for that lmao.

now, lets implement this!

local HttpService = game:GetService("HttpService") -- enable httpservice by doing game.HttpService.HttpEnabled = true inside command prompt
local MPS = game:GetService("MarketplaceService") -- marketplaceservice

local function getLatestAsset()
	
	local success, assetId = pcall(function()
		local latestAssetId 
		
		local assetsResponse = HttpService:RequestAsync({
			Url = "https://catalog.roproxy.com/v1/search/items?category=Accessories&limit=120&sortType=3&subcategory=Accessories", -- the url
		})
		local assetsBody = HttpService:JSONDecode(assetsResponse.Body) -- get the body from our response(the body is the data that was returned)
		
		
		-- next we need to see if you request to roblox api failed, 
		-- if so, we throw an error which will be catched by our catch block
		
		if not assetsResponse.Success then
			error(string.format("%s %s", assetsResponse.StatusCode, assetsResponse.StatusMessage)) -- throw an error with the status code and status message
		end
		
		for _, item in pairs(assetsBody.data)  do
			local assetId = item.id	
			local assetInfo = MPS:GetProductInfo(assetId, Enum.InfoType.Asset)
			
			local createdDate: string = assetInfo.Created
			local updatedDate: string = assetInfo.Updated
			
			local createdDateSplit = createdDate:split("-")
			local createdYear = createdDateSplit[1]
			local createdMonth = createdDateSplit[2]
			local createdDay = createdDateSplit[3]:sub(1, 2)
			
			local updatedDateSplit = updatedDate:split("-")
			local updatedYear = updatedDateSplit[1]
			local updatedMonth = updatedDateSplit[2]
			local updatedDay = updatedDateSplit[3]:sub(1, 2)
			
			
			if createdDay == updatedDay and createdMonth == updatedMonth and createdYear == updatedYear then
				latestAssetId = assetId
				break
			end
		end
		return latestAssetId -- return latest assetId
	end)
	
	if not success then
		warn(string.format("Failed to get latest asset because: %s", assetId)) -- send a warning in the output to tell u request failed
	else 
		print(string.format("Got latest asset B) asset id: %d", assetId)) -- print latest asset id
	end		
end

while true do
	getLatestAsset()
	task.wait(10)
end

this method isn’t 100% full proof, but it does the job.

and there you go, it gets the latest item that was created

Edit: another method is to get today’s UTC date and check it with the creation date. But this can cause inaccuracies with the system, so wouldn’t recommend

6 Likes

dang this is honestly really cool! but is there anyway to make it choose a completely random asset from the catalog?