Google Sheets User ID


I have made a Google Sheets system which takes a user’s ID and creates their thumbnail to display in a cell. However it is quite tiring manually putting in the user IDs when I already have their names.
Is there a way to take their username and retrieve their user ID?

You’re looking for the Users Api. Google Sheets has the ability to send requests which you can see at Class UrlFetchApp  |  Apps Script  |  Google Developers.

You can send a POST request to the API with the following JSON body:


  "usernames": [
  "excludeBannedUsers": true

The response you receive will then contain an id field with their userid if successful.

Where do you have the names? Is it a list?

Yeah, I have a column with names in each cell.

May I see, I can code you a quick thing that will convert all names into userIds

Copy all names and paste them here, I will respond with all the user ids.

Although I’d appreciate this, the sheet is more of a long-term thing, so having a solution that would work upon adding a name to the list would be great?

That would be kind of hard, maybe just userIDs only, so that’s already in the form you need.

Sorry, goes for this as well, would there be a solution which would work for each cell as they are updated frequently? Rather than having to give a list and keep updating that

I found an API which gives the userID based on username, I’m just struggling to extract that and put it into a cell. Any ideas?

APIs must be called, then parsed into data which can be put into the cells. I don’t think google sheets can do this automatically, you will need to use a separate program to do this, which is a pain in the ass.

I think there’s a pretty nice algorithm for this, assuming the UserId column is directly to the right of the Username column;

Note that this is insanely bad pseudocode to give you an example.

for row in rows:
    userid = POST username from row to API
    username_column = getcell curr_cell_column + 1
    username_column.update(userid) or similar

It’s a matter of looking through the Google Apps Script API, and googling questions each step of the way. e.g “update google sheets cell apps script” or “get next cell in range apps scripts”. You can start having a look here for examples. Class Range  |  Apps Script  |  Google Developers

I think there is Players:GetUserIdFromUsernameAsync or something similarly named but you should use that.