Getting Started With Automatic CSV Import
Staffbase offers a more advanced (new) CSV Import feature. Staffbase recommends switching to this new beta feature for advanced capabilities and better user experience.
User Management via automatic CSV import is one of the easiest and most scalable ways to manage your users on the Staffbase platform. The functions and capabilities that the automatic CSV import offer are the same as that of the manual CSV import performed in the Staffbase Studio. The only difference is that the script runs automatically on a schedule eliminating or reducing manual efforts. Similar to manual CSV import, for automatic CSV import, you need to actively push or upload the CSV file from your local environment to the Staffbase platform. You can do this with upload and update requests to the Staffbase endpoints. These calls are always performed in succession for the automatic CSV import.
Staffbase supports both complete and partial CSV automatic imports. The implementation for both processes is similar. If you use the partial CSV import, you need to define the partialImportTag
parameter for it in the code.
Contact support@staffbase.com to enable partial CSV import for your organization before implementing it.
Use this guide to get started with the automatic CSV import. The examples provided in the instruction use the
If you are using PowerShell for automating your CSV import, contact support@staffbase.com to receive template scripts for using PowerShell v5 or higher.
If you already have existing users in the platform, ensure the identifiers are set and match the identifiers in the CSV file.
The process of performing an automated CSV import in a nutshell.
HTTP POST
request to /users/import/csv/upload with the CSV file specified.HTTP POST
request to /users/import/csv/update with dry=true
.HTTP POST
request to /users/import/csv/update with dry=false
.In this guide, the following CSV file is used:
You can find more CSV file examples on our Support Portal.
Make an HTTP POST
request to the endpoint: /users/import/csv/upload with the following details:
Parameter | Description |
---|---|
Host | The base URI for the hosting infrastructure on which your app is hosted. |
Authorization | The API token to authorize the upload and update requests. |
CSV | The path of the CSV file in your local environment. |
Encoding | The character encoding used in the CSV file.
|
Field separator | The field separator used in the file to separate the values.
|
Partial import tag | The parameter for the partial CSV import. This is required only if you want to implement a partial CSV import. |
The following cURL-command uploads a new CSV file named users_example.csv
from the current directory, prettyprints the response (using json_pp
) and stores it in upload.json
.
For debugging purposes, inspect the upload.json.
For example, if you are using Linux environment, inspect the dry_run.json with cat dry_run.json.
Map the CSV attributes to the Staffbase Studio profile fields and upload the file to Staffbase using the HTTP POST
method to the endpoint /users/import/csv/update.
On the CSV Import Mappings page you can find an overview of available attributes in the platform and how to map them with your CSV file.
You can map one column from your CSV file to multiple fields. For example, identifier
maps the externalId
and userName
based on the same column.
Use the following parameters to:
While you can choose between English and German for the email invitation when manually creating a user in the Staffbase Studio, this is not the case with a CSV import.
The email invitation is sent based on the user’s content language. If the user’s content language isn’t English or German, there is a fallback for the invitation to English.
Preview the CSV to check all the changes you’re about to make are correct. The preview contains all the changes, such as created, updated, or deactivated users. In addition it may contain, warnings or errors, if any. For example, if you are using Linux environment, inspect the dry_run.json with cat dry_run.json.
See also the CSV Import References page to help you analyze your CSV import and get more information on potential warning and error codes.
After testing the mapping, you can set the parameter dry
to false
and import the file.
Use the example request code snippet from step 2 and modify the dry parameter.
Schedule the imports and updates based on your business requirements. You can use any scheduling tool of your choice. For example, if you’re using the cURL command-line for Unix or Linux, you can use the cron job command for scheduling.
It is recommended to check the state of your CSV import periodically to ensure everything is working as expected. This can also help if you want to run multiple partial imports in succession.
A HTTP GET request to the /users/import/csv/latest endpoint will return information on the latest import. The response will contain the completed
and running
parameters that will describe the state of the import.
The combination of these parameter’s values will provide you with the status of the import.
Parameter Values | Import State |
---|---|
completed: true running: false | Status: Completed Import is complete and the system is ready for another import. |
completed: false running: true | Status: In Progress The import is currently running on the system. |
completed: false running: false | Staus: In Preparation The first step (/users/import/csv/upload) of the import was completed and the second step (/users/import/csv/update) has not yet been started. The current import must be either completed by running the second step of the process or removed. |
The system will be ready for a new import when the status is Completed. If the parameters describe an In Progress or In Preparation status, a new import cannot be started.