# .csv upload for bulk user custom field changes

**URL:** https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619
**Category:** Feature
**Created:** [February 17, 2022, 9:38pm UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619 "2022-02-17T21:38:48Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [February 17, 2022, 9:38pm UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/1 "2022-02-17T21:38:48Z")

</div>

It would be super helpful to have the ability to upload a .csv (much like bulk invites) which contained the following:

1. username
2. custom field name
3. custom field value

And then have this data directly applied to the users’ accounts. Only if the username and custom field name are valid of course!

This would help enormously with data tidy-up exercises and migrations, which appear to be darn tricky with user custom fields.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 18, 2022, 12:18am UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/2 "2022-02-18T00:18:11Z")

</div>

If it’s for an import then it’s easy to do it in the importer.

You might also use the API.

Is hard to imagine acsv upload solution that would be easier.

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [February 18, 2022, 3:41am UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/3 "2022-02-18T03:41:24Z")

</div>

Well, my use case is for restoring some user custom fields which I inadvertently wiped for a bunch of users (see [Manipulating custom user fields from the Rails console](https://meta.discourse.org/t/problem-with-manipulating-custom-user-fields-from-the-rails-console/218613)). I’ve got the backup on a staging site, and I’ve also got them as a .csv

When you say ‘easy’ I’m guessing you mean it would take you a few hours to bash something out that would do the job. Can you give me a cost estimate?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 18, 2022, 10:42am UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/4 "2022-02-18T10:42:04Z")

</div>

Send me an email with details.

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [March 21, 2022, 11:10pm UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/5 "2022-03-21T23:10:34Z")

</div>

Jay has delivered the goods:

[https://github.com/pfaffman/import-user-fields-from-csv](https://github.com/pfaffman/import-user-fields-from-csv)

It requires some competence with Linux / Bash in order to use it, and I’d strongly recommend doing a backup first and doing it at a quiet time as you can royally stuff up your user data if not careful. I trialled it on a staging server before using it on our production site.

You might find this [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query useful in order to get the existing data for the `user_field` that you are targeting:

```plaintext
--[params]
-- string :ucf_name = user_field_1

SELECT
    user_id, value as ":ucf_name"
    
FROM user_custom_fields

WHERE name = :ucf_name
ORDER BY user_id asc

```

Note that you’ll have to remove the `'` from either side of the field name in the .csv as I couldn’t work out how to stop the query including them.

---

<div class="post-metadata">

### Author: ![selfaware](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@selfaware](https://meta.discourse.org/u/selfaware)
#### Post date: [January 18, 2024, 2:51pm UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/6 "2024-01-18T14:51:46Z")

</div>

Thank you for creating this script:

It would be nice if there was simply a upload option when creating the user field  
or an upload when creating tag groups.

Can you upload a picture that shows how the data should be formatted in excel.

Thank you!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [January 18, 2024, 4:55pm UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/7 "2024-01-18T16:55:56Z")

</div>

> [@](#):
>
> One column must contain the `user_id` (not `username` ). Custom user fields have internal names like `user_field_1` , so the other columns need to have those as column names.

| Column 1 | Column 2 | Column 3 |
| --- | --- | --- |
| user\_id | user\_field\_1 | user\_field\_3 |
| 4 | value | hello |
| 3 | another value | world |
| 6 | still another | banana |

---

<div class="post-metadata">

### Author: ![selfaware](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@selfaware](https://meta.discourse.org/u/selfaware)
#### Post date: [January 18, 2024, 6:26pm UTC](https://meta.discourse.org/t/csv-upload-for-bulk-user-custom-field-changes/218619/8 "2024-01-18T18:26:35Z")

</div>

Thank you!
