Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!

Qlik Cloud: use qlik-cli to import list of users from a csv file

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Daniele_Purrone
Support
Support

Qlik Cloud: use qlik-cli to import list of users from a csv file

Last Update:

Mar 5, 2024 3:58:31 AM

Updated By:

Daniele_Purrone

Created date:

Feb 23, 2024 5:18:12 AM

Attachments

Using the qlik-cli it is possible to import a list of users to a tenant from a csv file.
It will be then possible to assign roles, entitlements and space permissions to the users before they log in to the tenant.


Here's a possible example of how to do that.

  1.  Create a csv file called userlist.csv in this format (see attached sample file)

    Name,Email
    Mick Case,Mick.Case@example.com
    Davide Bironi,Davide.Bironi@example.com
    Kenny Handsley,Kenny.Handsley@example.com
    Leigh Kersriver,Leigh.Kersriver@example.com
    Gerry Vain,Gerry.Vain@example.com
    Tommy Ioni,Tommy.Ioni@example.com
    Terence Attendant,Terence.Attendant@example.com
    John Oughborne,John.Oughborne@example.com
    William Guard,William.Guard@example.com
    Renato Padovano,Renato.Padovano@example.com​


  2. Save the following shell script and put it in the same folder as the csv file

    1. Powershell version (note: if the location of the qlik-cli is not added as an Environment Variable Path you will need to modify the script to include the full path in front of the command "qlik")  

      # Import the csv file as an array of objects
      $csv = Import-Csv -Path userlist.csv
      # Initialize a counter for the subject
      $counter = 1
      # Loop through each object in the array
      foreach ($row in $csv) {
          # Generate the subject using the counter
          $subject = "ExampleSubject" + $counter
          # Execute the qlik-cli command with the column values and the subject
          qlik user create --name $row.Name --email $row.Email --subject $subject
          # Increment the counter
          $counter++
      }​

       

    2. Bash version for UNIX systems:

      #!/bin/bash
      # Get the number of lines in the csv file
      lines=$(wc -l < userlist.csv)
      # Loop from the second line to the last line (skipping the header row)
      for ((i=2; i<=lines; i++))
      do
        # Get the name and email values from the ith line using cut
        name=$(cut -d, -f1 userlist.csv | sed -n "${i}p")
        email=$(cut -d, -f2 userlist.csv | sed -n "${i}p")
        # Generate the subject using the counter
        subject="ExampleSubject$counter"
        # Execute the qlik-cli command with the column values and the subject
        qlik user create --name "$name" --email "$email" --subject "$subject"
        # Increment the counter
        ((counter++))
      done​
  3. Execute the scripts according to your operating system requirements

NOTE: users will be created with a temporary SubjectId like "ExampleSubject1", "ExampleSubject2", and so so on. After the first login, users will get a proper SubjectId. 
Roles, entitlements and space permissions will follow the users to the new subject.

 

Alternatives ways of adding users via scripts might be achieved via the an /api/v1/users CALL with the POST method and a payload like:

 

 

 

PAYLOAD:             
{
  "email": "name@example.com",
  "name": "First Lastname",
  "subject": "SubjectXYZ"
}

 

 

 



 

The information and the files in this article are provided as-is and will be used at your discretion. Depending on the tool(s) used, customization(s), and/or other factors, ongoing support on the solution below may not be provided by Qlik Support.

 

Environment

Labels (1)
Comments
ksuto
Partner - Creator
Partner - Creator

Hello.
Please tell me about the following message.
>It will be then possible to assign roles, entitlements and space permissions to the users before >they log in to the tenant.

As shown in the attached capture, I edited the csv file and PS1 file and ran it, but an error appeared and I could not run it.

Please provide specific examples of assigning roles, qualifications, and space permissions.

I'm using a translation, so I'm sorry if the English is hard to understand.
We apologize for any inconvenience this may cause and appreciate your understanding.

▼csv

ksuto_1-1726580780481.png

▼PSImportUsers.ps1

ksuto_0-1726580740568.png

▼Error
-----------------------------------------------------
Error: {
"traceId": "19c53014a34ead2c7fe8753d82654bc3",
"errors": [
{
"code": "IDENTITIES-11010",
"detail": "validation error: unable to match all requested documents for field \"roles\"",
"meta": {
"numExpected": 1,
"numFound": 0
},
"source": {
"pointer": "/roles"
},
"status": 400,
"title": "Bad Request"
}
]
}

 

Daniele_Purrone
Support
Support

Hi @ksuto ,

 

I see a typo in your csv file: "Proffesional", instead than "Professional"

That could be the cause.

ksuto
Partner - Creator
Partner - Creator

@Daniele_Purrone 

I edited the misspelling of Professional, but it didn't work.
I think there may be an error in the "Flags" information in the capture below and the content added to the csv or PS1 file.

Which flag should I use for "TenantAdmin" and "Professional"?

ksuto_0-1727426356917.png

 

Daniele_Purrone
Support
Support

Hi @ksuto : I did some testing. For roles like "TenantAdmin" the flag to use is "--role"

Entitlements, however, cannot be assigned using the "user" command.
You will need to use the "license" one.

Contributors
Version history
Last update:
‎2024-03-05 03:58 AM
Updated by: