How to set user's location string with Discourse API

AI-generated summary

A user is trying to set a user’s location string using the Discourse API. pnoeric found an endpoint to set a user’s info, but couldn’t figure out how to pass the user ID instead of the username and was getting a 404 error when posting to mydiscourse.com/u/my_user_name. codinghorror suggested using the “Reverse Engineer the Discourse API” method to spy on XHR requests. Following this advice, pnoeric was able to successfully update the custom fields by making a PUT request to /u/username.json. However, it appears that the API call can only be made with a username, not with a user ID.

It looks like there’s an endpoint to set a user’s info, including their location.

However, I can’t figure out:

  1. How to pass the user ID instead of the username?

  2. When I post a new location to mydiscourse.com/u/my_user_name, I’m getting a 404 error on return… not sure why. I’m using the same code that I used to post other things to the API. So I’m thinking that endpoint is wrong, even though it seems like that’s what in the API code. Am I just mis-reading the API code? [Edit: I tried adding .json to the endpoint, no luck]

Thank you,
E

See Reverse engineer the Discourse API while you execute that operation in the user interface.

Thanks Jeff, that was what I needed… being able to spy on the XHR requests directly is clever!

For others who might need the info: I was able to PUT to /u/username.json and update the custom fields that way. And it appears you can only make the call with a username, not with a user ID (too bad).