You have not completed all the user fields API error


(Nathan Hamilton) #1

Hello,

I am trying to create a user with the api and here is the curl request that I used:

curl -X POST "Content-Type: multipart/form-data;" -F "api_key=my_api_key" -F "api_username=my_api_username" -F "name=My Name" -F "email=email@test.com" -F "password=password" -F "username=username" "https://forums.lumerit.com/users"

The response that I receive is this:

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
{"success":false,"message":"You have not completed all the user fields"}

I also tried watching the network traffic through dev tools on my instance and creating a new user, but it was posting to /login not /users so I was greatly confused. Any help that someone could give me would be greatly appreciated.


(Blake Erickson) #2

I just tried the same curl command on my local and its working fine:

$ curl -X POST "Content-Type: multipart/form-data;" -F "apc5acaefaf303ce47e64dd3182947df42b74ceef7b99f4b726dcced111babd" -F "api_username=discourse1" -F "name=My Name" -F "email=email@test.com" -F "password=Strong123Blah" -F "username=discourse3" "http://localhost:3000/users"
curl: (6) Could not resolve host: Content-Type

{"success":true,"active":false,"message":"\u003cp\u003eYou're almost done! We sent an activation mail to \u003cb\u003eemail@test.com\u003c/b\u003e. Please follow the instructions in the email to activate your account.\u003c/p\u003e\u003cp\u003eIf it doesn't arrive, check your spam folder, or try to log in again to send another activation mail.\u003c/p\u003e","user_id":2}

You shouldn’t be getting a redirect to login though, is your forum private?


(Blake Erickson) #3

also use -H for setting the content type:

curl -X POST -H "Content-Type: multipart/form-data;"

(Nathan Hamilton) #4

Great catch, I forgot to add the -H for the header. So now it is returning simply:

{"success":false,"message":"You have not completed all the user fields"}


(Nathan Hamilton) #5

I believe that this error is being returned due to custom fields that need to be passed in, but I don’t know how to pass those to the API. The documentation is silent on how to deal with custom parameters.


(Blake Erickson) #6

Do you know what the custom fields are? I would try passing them in just like the other user fields:

-F "custom_field=value"

and see where that gets you.


(Nathan Hamilton) #7

So here are the fields:

curl -X POST -H "Content-Type: multipart/form-data;" -F "api_key=myapikey" -F "api_username=myapiusername" -F "name=Some Name" -F "email=email@test.com" -F "password=forum2017" -F "status=Freshman" "enrollment_date=Jan2017" -F "username=esquireofthelord" "https://forums.lumerit.com/users"

The status custom field is a dropdown and is required upon signup, the enrollment date is a string but is not required on startup. Could it be that the dropdown is causing issues?

Even though I have added these fields it still is returning the same response as earlier. And you asked if my forum is private, does that mean no one can signup for it publicly? If so, then partially. A user has to be approved before they can start using the forums.

Thanks for your help Blake.


(Blake Erickson) #8

I only asked if your forum was private because you were being redirected to /login earlier. So thats not the issue anymore.

I’m really note sure what your issue is because (this might be a “bug”) I added some required custom fields to my local discourse and they still aren’t being required by the api.

Looks like you are missing a -F before enrollment_date

I would try removing all your custom fields for now and see if you can get it to work. Then add them back in one by one.

I would also suggest using postman for testing out your API requests instead of curl.


(Nathan Hamilton) #9

So I was able to get it to work by using user_fields[1] as shown below. This was made known to me by watching the network traffic while signing up on our domain and zoning in on the /users POST request.

curl -X POST -H “Content-Type: multipart/form-data;” -F “api_key=myapikey” -F “api_username=discourse1” -F “name=full name” -F "email=myemail@test.com" -F “password=newpass” -F “user_fields[1]=Freshman” -F “user_fields[5]=Jan2017” -F “username=myusername” -F “active=true” “Unbound Forums

I have seen this issue being addressed here: Getting " You have not completed all the user fields" error while creating user using PHP API

However, I would like to ask that the documentation for the API be updated as it says nothing about custom fields: Discourse API Docs

Thanks for your help Blake!