Hey there!
I’m in the process of making a web admin panel for my Roblox game, but am having trouble using the Roblox API. What this script is suppose to do is get the user id of the username that was entered into the text box, but I can’t seem to get it working and was hoping someone could help me out.
Code:
<script>
document.getElementById('searchForId').addEventListener('click', getUserID);
async function getUserID() {
const username = document.getElementById('result').value.trim();
const url = `https://users.roblox.com/v1/usernames/users`
const response = await fetch(url, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"usernames": [username],
"excludeBannedUsers": false
})
});
const data = await response.json();
if (data.data && data.data.length > 0) {
const userId = data.data[0].id;
document.getElementById('result').textContent = `User ID: ${userId}`;
} else {
document.getElementById('result').textContent = 'User not found on Roblox';
}
}
</script>
2 Likes
I have changed the method to both ‘POST’ and ‘GET’ and none of them work. Here are the errors I get
2 Likes
Mikixxx0
(Dreamy)
July 21, 2024, 7:52am
#3
You’re trying to access the Roblox API, which is now blocked. Try using a proxy like ‘roproxy’. Change your url to “https://users.roproxy.com/v1/usernames/users ” or just add your own proxy.
3 Likes
I’ll give it a try and see if it works, Thanks
3 Likes
I changed the URL to that one, and nothing happens, I don’t get any errors, doesn’t show the user id, nothing in the console either
2 Likes
Mikixxx0
(Dreamy)
July 21, 2024, 8:12am
#6
Change the method to “GET”.
GET Method: Used to retrieve information from the server.
POST Method: Used to create or update a resource .
2 Likes
So just change the URL and Method?
2 Likes
Here’s the new code
<script>
document.getElementById('searchForId').addEventListener('click', getUserID);
async function getUserID() {
const username = document.getElementById('result').value.trim();
const url = `https://users.roproxy.com/v1/usernames/users`
const response = await fetch(url, {
method: "GET",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"usernames": [username],
"excludeBannedUsers": false
})
});
const data = await response.json();
if (data.data && data.data.length > 0) {
const userId = data.data[0].id;
document.getElementById('result').textContent = `User ID: ${userId}`;
} else {
document.getElementById('result').textContent = 'User not found on Roblox';
}
}
</script>
I got it working, I had to move the button event and change GET to POST
Mikixxx0
(Dreamy)
July 21, 2024, 8:21am
#11
Yeah, I’ve realized just now that it needs to be post instead of get. In the future use roproxy, instead of the roblox api, because most of the api is blocked.
1 Like
Alright, Thank you so much! Have a nice day/night!
1 Like
system
(system)
Closed
August 4, 2024, 8:22am
#13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.