Disable account confirm emails when creating users via API

If the user was actually created the user_id will be in the response. But considering you can’t find the user in the admin dashboard they probably weren’t created for some reason.

Ah okay, so you are creating an importer. You do not want to do this though API calls, but you want to create an importer script and run it directly from inside of your docker container.

I would look at one of the many examples listed in discourse/script/import_scripts at main · discourse/discourse · GitHub

May I ask why?
(I have admin access to Discourse, but not to the server/docker container, so I would have to ask someone else to do that.)

Seems so! Are there any known causes for that? Something in the settings?

It is 100x faster if it is a large import and you get direct access to the the ImportScripts::Base class methods that make is super easy to create users and many other things for imports like creating groups, categories, topics and posts:

You could create the script and have them run it if need be.

No known issues around this. Here is an example curl request to create a user:

curl -i -sS -X POST "http://localhost:3000/users" \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: ****" \
-H "Api-Username: system" \
-F "name=cfbcc77ae9f4230d2c25" \
-F "username=cfbcc77ae9f4230d2c25" \
-F "email=cfbcc77ae9f4230d2c25@example.com" \
-F "password=3f348653105f05505f5f1a3ff70ef984" \
-F "active=true" \
-F "user_fields[1]=cfbcc77ae9f4230d2c25" \
-F "user_fields[2]=828c0ec3a76"

which returns:

{"success":true,"active":false,"message":"\u003cp\u003eYou’re almost done! We sent an activation mail to \u003cb\u003ecfbcc77ae9f4230d2c25@example.com\u003c/b\u003e. Please follow the instructions in the mail to activate your account.\u003c/p\u003e\u003cp\u003eIf it doesn’t arrive, check your spam folder.\u003c/p\u003e","user_id":4}

It’s possible something has changed because it looks like emails are being sent now, but the user is still being created. Looks like the active=true isn’t being applied.

1 Like

I should also admit that I have no knowledge of Ruby :man_facepalming:

So I will try to investigate the issue with API a bit further. Will try to run a call similar to yours. Just a few things to clarify:
a) The endpoint is [mydomain]/users.json, right?
b) Content-Type should be "multipart/form-data" or "application/json", as written in the API docs?
c) What are "user_fields" for?

1 Like

Yes, usually you want to append .json to all routes. Yes, you can also use application/json for the content-type and the user_fields are optional, it was just part of my example script I already had.

2 Likes

It worked!

Sending exactly the same curl request as yours (with my data) resulted in the creation of an activated user.
Not sure yet, why it didn’t work for me originally when I was sending similar requests from Postman. I will further investigate this issue, and report here if I find anything significant.

Thank you for your help!

2 Likes

This has been resolved with this commit:

https://github.com/discourse/discourse/commit/fec68d3d25bfc80d084af52e17882ad886fd5cd0

5 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.