Getting ID by username not working (Node.js)

Hello,

I am making a discord bot where you can search for Roblox users either by UserId or Username; Problem is, I can’t get the username part to work. I am using the user API to get the username, but the data is empty:

async function getUserIdByUsername(username) {
    const id_ = []
    try {
      const result = await 
fetch('https://users.roproxy.com/v1/usernames/users', {
        method: 'POST',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json'
        },
        body: {
          usernames: [
              username
          ],
          excludeBannedUsers: true,
        }
      })
      console.log(username)
      const json_res = await result.json()
      console.log(json_res)
      id_.push(json_res['data'][0]['id'])
    } catch(err) {
        throw new Error('Invalid username!', err);
    }
    return id_
}

image
Help is appreciated

Why are you using a proxy? Also it appears the api URL I have used in the past is returning 404,

{"errors":[{"code":404,"message":"NotFound"}]}

https://api.roblox.com/users/get-by-username?username=claym1x

Maybe try to use a module like Noblox.js

Either way, if I use a proxy or not, it still returns an empty data array.
image
How would I use Noblox.js? I installed it.

try using this endpoint:
https://users.roblox.com/v1/users/search?keyword=username&limit=10 then just do data[0] .id and it will return the person with the exact userid most of the time.

Noblox.js worked, thank you. chrrrr

1 Like

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