How do I import a list of users using the Flexopus API?

In this article you can find out how to create an API token and use it to import a complete user list in a spreadsheet format.

Generate an API token

As a system administrator go the administrator dashboard and select the "Single Sign On / Integrations" tab in the "Settings" menu. Here you can generate a token for our API in the "Flexopus API" section.

⚠️ Copy and save your token in a safe and secure place as you will not be able to look at it again. In case you ever lose your token, you will have to generate a new one and replace it everywhere you use it.

Import users using the API endpoint

Use the following endpoint:

POST /api/v1/users/import

The endpoint uses the Bearer Token generated above for authentication and accepts multipart data as input:

  • file: file; required; accepted file formats: csv, txt, ods, xls, xlsx; should contain the user list to be imported
    ℹ️ Expected file structure and example file available at the link on the bottom of this page.
  • update: boolean; default false; determines whether existing users should be updated
  • deactivate: boolean; default false; determines whether users not present in the list should be deactivated
  • restore: boolean; default false; determines whether deactivated users present in the list should be re-activated
  • dry_run: boolean; default false; in case this flag is true, the actions are not carried out for real but simulated so the user can check the results without making modifications

The endpoint return JSON data in the following format:

{
"dryRun": false,         // dry_run flag from the request
"created": [2, 3],       // row indices for freshly created users
"updated": [4, 6],       // row indices for updated users
"deleted": 0,            // the number of deleted users
"skipped": [5, 8],       // row indices for unchanged users
"errors": [7],           // indices for rows with errors
"errorMessages": {       // object with messages for every error
  "7": {                     // row index of error
    "email": [                   // column with error
      "The email must be a valid email address." // error message
      ]
    }
  },
"rows": 7, // total number of processed rows
"filename": "users.csv" // name of the uploaded file
}

Here is an example using the curl program:

curl https://<your-domain>.flexopus.com/api/v1/users/import \
-H "Accept: application/json" \
-H "Authorization: Bearer <your-token>" \
-F "file=@./users.csv" \
-F "update=1" \
-F "deactivate=1" \
-F "restore=1" \
-F "dry_run=0"

This example will:

  • deactivate every user not present in the users.csv file
  • create every user present in the users.csv file but not present in the system
  • update and (if deactivated) re-activate every user present both in the users.csv file and the system

ℹ️ You can read more about the expected structure of the import file at
https://<your‑domain>.flexopus.com/dashboard/users/import-export

R0076