How to decode this data right?

Hi, i’ve read the documentation on the External Catalog API Documentation, and in this code, i tried to get a random decal from the catalog and get information from it, and i can’t seem to get it to work? (The data extraction doesn’t work)
here’s the function:

function module.GetRandomDecal()
	local decalData = {}
	local success = false

	while success == false do
			local url = ""
			local response = HttpService:GetAsync(url)
			local data = HttpService:JSONDecode(response)

			if data and then
				local decalInfo =[math.random(1,]
				if decalInfo and decalInfo.assetId then = decalInfo.assetId
					decalData.creatorID = decalInfo.creatorTargetId
					decalData.favoriteCount = decalInfo.favoriteCount
					decalData.creationDate = decalInfo.createdDate
					success = true


	return, decalData

The issue isn’t the decoding but the fetching of information. Your query returns 0 results(an empty array). This is because you should pass the Keyword parameter in the url with a query of at least 2 characters long. Since this is supposed to be a random decal function, you can make another function for generating a random query and passing that:

local function pickRandomLetter(alphabet: string): string
	local x = math.random(1, alphabet:len())
	return alphabet:sub(x, x)

--modify this as you wish
local function generateRandomQuery(queryLen: number): string
	--characters to use in random query
	local alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
	local result = ""
	for i = 1, queryLen do result ..= pickRandomLetter(alphabet) end
	return result

local keyword = generateRandomQuery(2)
local url = ""..keyword
--fetch the url with the randomized query here
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.