How to bulk load users

Notes for how to bulk load users

This guide shows how to script the user creation process using the CHT API directly. User creation can also be scripted using the cht-conf tool, which is detailed in the CSV-to-Docs guide.

First, using the webapp, create the top level places/facilities like districts/branches that the users will belong to. Save the UUIDs of these places in a spreadsheet with their names.

Then use curl against the users API to create the user, place and contact. In this example the place and contact.parent are the same so we’re creating demo* users that can manage records associated to a specific place.

Create a comma separated data file like /tmp/data:

Name,Phone,Branch Name,Branch UUID,Username,Password
Gary Gnu,48839938,Iganga Branch,54cc7-accd-e1cf9-ef203,demo01,keratejevu
Dianna Dempsey,4999393,Meru Branch,54cc1-1a7a-ccddd-e1203,demo02,duwuradixu

Create a script like users-bulk-load and edit it to include the district:



LANG=en # no language prompt, please.
KNOWN=true # no tour, please.
IFS=$',' # comma delimited

while IFS=$IFS read name phone district uuid username password; do \
  curl -v -H 'content-type:application/json' -d '{
    "place": {
      "name": "'"$name Area"'",
      "type": "health_center",
      "parent": "'"$uuid"'"
      "phone": "'"$PHONE_PREFIX$phone"'"
  }' "$COUCH_URL/api/v1/users";

Load the data into the loop:

tail -n+2 /tmp/data | COUCH_URL= \
  users-bulk-load # tail skips header row