Updating a Custom User Field through the Discourse API can be achieved by sending a PUT request with the correct payload. The payload is not in JSON format, but rather in form data, with the user field value encoded as user_fields%5BID%5D=value (e.g., user_fields%5B8%5D=test).
To update a single user field, use the following format: user_fields%5BID%5D=value, where ID is the ID of the user field to be updated.
However, as Richie discovered, the API call may not work if performed by the user, due to a site setting that prevents editing of user fields by users. To circumvent this, Richie recommends reworking the API call to be performed by the system instead.
I’ve been trying to reverse engineer the updating of a user_field value.
I did this by following the steps in Reverse engineer the Discourse API, I edited a test user and made a note of what was occurring in the network tab of the browser.
I can see that I need to PUT to this url: https://example.com/u/my-username-here.json
Where I got a bit confused was by not seeing a json payload but instead it’s some formdata. The payload was: user_fields%5B1%5D=some+dji%2C+some+Autel&user_fields%5B5%5D=%40UKDroneClub&user_fields%5B6%5D=%40iKiteFlyer&user_fields%5B8%5D=test&timezone=Europe%2FLondon&default_calendar=none_selected
I only wish to update one user_field value,
It’s URL encoded: user_fields%5B8%5D=test
And decoded, it reads as: user_fields[8]=test
(8 = the id of the user_field I want to update)
How would I convert this form data value in to a json payload so I can then PUT it?
I’m not sure what I’m doing wrong here but I am able to update the About Me section of a users profile via an API call, but I cannot update any of the user_fields.
If I monitor my browser when editing a user, I can see it PUTing the following: