How to get the name of an asset by assettypeId?

Hello, I am trying to get the AssetType (string) from the AssetTypeId (number) of an object. Right now, I’m calling items by http service and It only gives me a AssetTypeId.

I’m trying to display an image of the object however the object can be any type of asset so i have to make Roblox determine it.

I’m looping through the table and I’m creating a new image label, then I’m setting the image to the assets image. Here’s my code:

	for i,v in pairs(Suspected.Favorites) do
		local clone = Results.All.Template:Clone()
		clone.Parent = Results.All
		clone.Image = "rbxthumb://type=Asset".. game:GetService("MarketplaceService").GetProductInfo(2).AssetType .."&id="..v.Item.AssetId .."&w=150&h=150"
	end

(I didn’t actually know what I was doing and was going off of a google search when i said this:)

game:GetService("MarketplaceService").GetProductInfo(2).AssetType 

You’re getting the product info of the asset id ‘2’. Why?

Like I said it was me making a wild guess so I wasn’t expecting it to work (which it didn’t)

What is Suspected.Favorites? Does it contain a list of asset ids for images?

Yes. Here’s all the information it provides for each asset as well:

                ["Favorites"] =  ▼  {
                   [1] =  ▼  {
                      ["AssetRestrictionIcon"] =  ▼  {
                         ["HasTooltip"] = false,
                         ["LoadAssetRestrictionIconCss"] = true
                      },
                      ["Creator"] =  ▼  {
                         ["CreatorProfileLink"] = "https://www.roblox.com/users/909560737/profile/",
                         ["HasVerifiedBadge"] = false,
                         ["Id"] = 909560737,
                         ["Name"] = "Wseall_UTUBE",
                         ["Type"] = 1
                      },
                      ["Item"] =  ▼  {
                         ["AbsoluteUrl"] = "https://www.roblox.com/library/4479328887/Removed-for-copyright",
                         ["AssetCategory"] = 0,
                         ["AssetId"] = 4479328887,
                         ["AssetType"] = 3,
                         ["CurrentVersionId"] = 0,
                         ["IsApproved"] = false,
                         ["LastUpdated"] = "/Date(-62135575200000)/",
                         ["Name"] = "(Removed for copyright)"
                      },
                      ["Product"] =  ▼  {
                         ["BcRequirement"] = 0,
                         ["Id"] = 0,
                         ["IsForSale"] = false,
                         ["IsFree"] = false,
                         ["IsLimited"] = false,
                         ["IsLimitedUnique"] = false,
                         ["IsPublicDomain"] = false,
                         ["IsResellable"] = false,
                         ["NoPriceText"] = "Offsale",
                         ["SellerId"] = 0,
                         ["TotalPrivateSales"] = 0
                      },
                      ["Thumbnail"] =  ▼  {
                         ["Final"] = true,
                         ["IsApproved"] = false,
                         ["RetryUrl"] = "",
                         ["Url"] = "https://t7.rbxcdn.com/7c76cda92a72f981fc75cf114594cf18"
                      },
                      ["UserItem"] =  ▼  {
                         ["CanUserBuyItem"] = false,
                         ["IsItemOwned"] = false,
                         ["ItemOwnedCount"] = 0
                      }
                   }
1 Like

Are you trying to get the game icons of all the user’s favorite games?

Close but no. I’m trying to get the icons of all the users favorites in total.
(Yes you heard me right, all of it)

Well if you want the game icon of a user’s favorite game, this asset url might work:

"rbxthumb://type=GameIcon&id="..v.Item.AssetId.."&w=150&h=150"

Not sure if the AssetId has to be the game’s PlaceId or GameId/UniverseId though.

The method I’m using is universal however the name isnt.
I wanted to ask if it was possible to automatically detect the name of the assetype with the information I have of the product

Yeah, you can do:

game:GetService("MarketplaceService"):GetProductInfo(id).AssetType 

as you said before. Btw, this may be useful to you:

It says MarketplaceService:getProductInfo() failed because HTTP 400 (Bad Request)

my code:

clone.Image = "rbxthumb://type=".. game:GetService("MarketplaceService"):GetProductInfo(v.Item.AssetType).AssetType  .."&id="..v.Item.AssetId .."&w=420&h=420"

Enable HTTP requests.

Game settings > Security > Allow HTTP requests


If http wasnt enabled I wouldnt be able to get the list of favorites in the first place lol

change this to AssetId, not AssetType.
Although, why don’t you just do this?

clone.Image = "rbxthumb://type=".. v.Item.AssetType  .."&id="..v.Item.AssetId .."&w=420&h=420"

The reason I dont do this is because the AssetType in the list I’m using is a number. If i run your code it will just do this:

clone.Image = "rbxthumb://type=GameIcon&id="..v.Item.AssetId .."&w=420&h=420"

or

clone.Image = "rbxthumb://type=GameThumbnail&id="..v.Item.AssetId .."&w=420&h=420"

Hey thanks for helping but like I said before, It has to be universal

maybe I wasn’t clear before: IM NOT JUST GETTING THEIR FAVORITE GAMES
I’m getting ALL their favorites (avatar items, games, etc)

Oh wait I’m seeing now, and I just realized that you weren’t the person I told that to previously to lol. Sorry if that came off as aggressive, It’s just I’m reexplaining it lol
image

Oh, yeah, that’s my bad. But, couldn’t you just get the assetType from the Enum AssetType list?

function getAssetType(assettype)
	for i, v in ipairs(Enum.AssetType:GetEnumItems()) do
		if assettype == v.Value then
			return v.Name
		end
	end
end

--later in the code

clone.Image = "rbxthumb://type="..getAssetType(v.Item.AssetType).."&id="..v.Item.AssetId.."&w=420&h=420"

Also, it’s fine, I understand the pain of repeating yourself multiple times, typically worse for the same person lol

What are you trying to use this for? there might be an easier solution.