GitLab: how add users in bulk

For this task we will use the GitLab API.

1. Obtain the PRIVATE-TOKEN

Do you need a token to prove to be authenticated

giovanni@vm-gittest:~/git$ curl "http://vm-gittest.us.archive.org/api/v3/session" --data 'login=root&password=ThePassword'  | python -mjson.tool
 
{
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd197acbd4d13d7dd61?s=40&d=identicon",
    "bio": null,
    "can_create_group": true,
    "can_create_project": true,
    "color_scheme_id": 1,
    "created_at": "2015-03-23T17:41:18.649Z",
    "email": "admin@example.com",
    "id": 1,
    "identities": [],
    "is_admin": true,
    "linkedin": "",
    "name": "Administrator",
    "private_token": "2xyxyxysyxsyxsUe8",
    "projects_limit": 10000,
    "skype": "",
    "state": "active",
    "theme_id": 2,
    "twitter": "",
    "username": "root",
    "website_url": ""
}

2. Create the users

You can add a new user on GitLab using the command:

curl --header "PRIVATE-TOKEN: YourPrivateToken" -d "email=user@archive.org&password=defaultPassword&username=username$name=name" "http://vm-gittest.us.archive.org/api/v3/users"

To add users in bulk we need a file containing all the users to be created like:

mark = mark <mark@archive.org>
zella = zella <zella@archive.org>
uie = uie <uie@archive.org>
kers = kers <kers@archive.org>
.....

and run the command:

for i in `cat authors-transform.txt | awk {'print "email="$1"@archive.org&password=defaultPassword&username="$1"&name="$1""'}`; 
   do  curl --header "PRIVATE-TOKEN: YourPrivateToken" -d $i "http://vm-gittest.us.archive.org/api/v3/users"; 
done

WARNING: at this point all the users will receive a confirmation email to activate their account.