Incorrect user_field information - API docs

AI-generated summary

Users reported inconsistencies in the Discourse API documentation regarding the correct format for creating user fields via the REST API. zsan noted that the documentation showed multipart/form-data syntax but labeled it as application/json, leading to confusion. blake, who authored the docs, confirmed the error and clarified that when using application/json, the correct format is nested JSON like { "user_field": { "name": "...", "field_type": "...", ... } }. JamesNorth added that creating a new user with required user fields also required correct JSON formatting, such as { "user_fields": { "1": "Required User Field Data" } }, which resolved their 24-hour debugging struggle. Blake acknowledged the mistake and updated the docs via pull request #30133 to align the examples with the actual application/json format. The confusion stemmed from mismatched content-type labeling in the docs, which has now been corrected.

create user field

I see

{
  "user_field[name]": "string",
  "user_field[description]": "string",
  "user_field[field_type": "string",
  "user_field[required]": true
}

Are you sure ?

I think it should be something like

{
  "user_field: {
     "name": "asdf",
     "description": "asdf",
     "field_type": "confirm",
     "required": true
  }
}

I believe that @blake wrote that documentation so let’s see what he reckons here.

Yes, if you are using Content-Type: application/json you should send it in like

The example in the api docs is using Content-Type: multipart/form-data, but I’ll be sure to update it to the json example.

Thank you @blake

Note:
The problem is .. i see application/json in the example (so that’s why my partner spent all hours to figure it out how to use this call)

I also struggled for about 24 hours solid with this as the docs example suggests application/json formatted requests for creating a new user be boolean for user_field …

I was being told I hadn’t finished all the required user fields … but in my case I have an existing required user_field I need to enter data into that field and it should be formatted like this:

{
  "name": "Full Name",
  "email": "email@address.com",
  "password": "348hqpwfaed",
  "username": "UserName",
  "user_fields": {
    "1": "Required User Field Data"
  }
}

The above formatting worked for me.

Are the docs correct in this case for creating a new user?

Nope that was still the form-data format. I updated it to use json so that the example matches the format. Thank you for bringing this up!

https://github.com/discourse/discourse/pull/30133