API to get User ID from Username?

So I have been researching this, im building a roblox website (if interested message me),

and I am trying to get the persons user id from their username, and I have seen on the forum people saying do this: https://users.roblox.com/v1/usernames/users

But it is just giving me errors, anyone know why?

Oops nevermind

And if you go to the endpoint it says: message: MethodNotAllowed

1 Like

Its for a javascript website, not lua

1 Like

I meant this link I think

https://users.roblox.com/docs/index.html#!/Users/post_v1_usernames_users

1 Like

The issue you encounter is probably you making a GET instead of a POST request. A GET request is when you just fetch a page(like when opening it for view in browser). POST requests on the other hand are mostly made programmatically and their parameters are hidden(instead of visible within the url).

For this you need to make a POST request to https://users.roblox.com/v1/usernames/users with the following data:

{
  "usernames": [
    "targetUsernameHere"
  ],
  "excludeBannedUsers": false
}

It should return a json encoded string, if you decode that string and get the data structure your code can understand you can then find the user id by looping through all the values of responseContent["data"] and returning the value["id"] of the first value you find that meets the condition value["requestedUsername"] == "targetUsernameHere". If you only request a single username however(like we do here), you can just do responseContent["data"][0]["id"] to fetch the user id assuming the arrays in said language start from 0(and not 1 like in lua).

3 Likes

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