I am in the process of developing a tool that retrieves ROBLOX asset IDs using this particular API. I am utilizing the product info function through an API GET request. Despite being near completion, I keep encountering the error
Uncaught (in promise) SyntaxError: Unexpected end of input at script.js:8:42
.
If anyone could lend a hand, I would greatly appreciate it!
Below is a link to my code.
JavaScript Code
function convert()
{
var input = document.getElementById("AssetConverterArea").value;
var output = document.getElementById("assetIdReturn");
var webRequest = fetch('https://api.roblox.com/marketplace/productinfo?assetId=' + input, {'mode': 'no-cors'});
var assetId = webRequest.AssetId;
webRequest.then(responce => responce.json()).then(d => {
console.log(responce)
assetId = d.AssetId;
});
if (assetId === undefined)
{
output.innerHTML = "Invalid Asset ID";
} else {
output.innerHTM = 'Your asset ID is: ' + assetId;
}
}
HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="icon" type="image/x-icon" href="Media/assetid.png">
<link rel="stylesheet" href="style.css">
<script src="script.js" defer></script>
</head>
<body>
<header>
<nav>
<ul class="navLinks">
<li class="navLink"><a href="index.html" class="navHref">Home</a></li>
<li class="navLink"><a href="credits.html" class="navHref">Credits</a></li>
<li class="navLink"><a href="about.html" class="navHref">About</a></li>
</ul>
</nav>
<span class="favicon"><img src="Media/assetid.png" alt=""></span>
</header>
<div class="line"></div>
<h1 class="title">Asset Converter</h1>
<p class="description">
This website is a simple tool to convert your Roblox decal & library IDs into Roblox Asset IDs. <br><span style="font-weight: 800;"> Thank you for checking out the website!</span>
</p>
</p>
<div class="AssetDiv"><textarea placeholder="Decal ID" id="AssetConverterArea"></textarea></div>
<button class="convertButton" onclick="convert()"><span class="convertText">Convert</span></button>
<p id="assetIdReturn">Convert your ID, and get a return!</p>
<p class="sourceCode">This entire project's source code is free for you to check out on <a style="color: rgb(73,0,250); text-decoration: none;" href="https://github.com/hartleyfr/RobloxAssetReturner/tree/main">my github</a></p>
</body>
</html>
I attempted to utilize CORS-Everywhere functions without success. Despite trying fixes from StackOverflow, the issue remains unresolved.
The expected behavior was as follows:
Retrieve the API return and table, locate the asset ID in the table, if the assetId cannot be found, display a message stating that the ID is invalid and prompt for another attempt. If found, display it to the user.