Import Users via CSV

I know there is a ‘frontend’ way to invite users via CSV, however that will not work in my case, as it will send an email to the thousands of people who will be added to the site.

When trying to add it via the CLI, I get the following errors.

/var/www/discourse# rails runner script/import_scripts/csv_importer.rb /var/www/discourse/tmp/users.csv
Loading existing groups…
Loading existing users…
Loading existing categories…
Loading existing posts…
Loading existing topics…
File doesn’t exist: /var/www/discourse/tmp/emails.csv
File doesn’t exist: /var/www/discourse/tmp/custom_fields.csv
bundler: failed to load command: script/rails (script/rails)
/var/www/discourse/script/import_scripts/csv_importer.rb:29:in initialize': undefined method headers’ for nil (NoMethodError)

@imported_custom_fields_names = @imported_custom_fields.headers.drop(1)
                                                       ^^^^^^^^

Any thoughts on what could be going on?

This script is a migration script, it’s not intended for doing the singular task of adding users.

Do you just want to create a larger number of real user accounts, or are they for testing?

Aha! I saw importer, not migration! Thanks for the tip.

I want to import a large amount of users via CSV

Import and migrate here are mostly synonyms.

It should do the job of creating all of those users (they won’t have passwords, so they’ll need to get one, probably by having an email sent to them).

You’ll likely need to understand a bit about programming to make it work.

First off - happy birthday.

I have next to no programming skills. I assumed it would be as simple as kicking off the import.rb file ‘pointed’ at the users.csv.

The errors it output make exactly zero sense to me. I looked at line 29 of the import script and it referenced headers, so I assumed it meant the columns of the csv file, so I spent some time mucking with that, to no avail.

Well, you didn’t get very far since it never even opened your csv.

It’s one of those frustrating things where it could take 30 seconds or hours.

But you might try copying the file to there. It’s tricky because it’s one place in the file system of the computer and another inside the container. Once you solve that you can start mucking with the column headings.

Sometimes there’s an easy solution to the original problem[1].

Disable emails, import the users, then re-enable emails.


  1. see x-y problem ↩︎

1 Like

Aha - but the issue here, is that I think the importer picked up the users.csv.

I don’t have or want to import emails.csv etc.

Or is this a multipart importer? Where users (names) are in one csv, and the amils are in another csv (emails.csv)

It looks like it is finding the users.csv file as it is not barfing an error about that one.