Learn how to get started using the (new) CSV Import API for managing your user base.
User Management via CSV Import API is one of the easiest and most scalable ways to manage users on the Staffbase platform. The functions and capabilities that the CSV Import API offers are similar to those of the manual CSV import in the Staffbase Studio. The main difference is that with the CSV Import API, the script runs on an automatic schedule. This reduces or eliminates manual efforts, and comes with some additional capabilities.
Similar to manual CSV import, you need to actively push or upload the CSV file from your local environment to the Staffbase platform for automatic CSV import. 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. With the CSV Import API, Staffbase supports both complete imports and selected user imports. The selected user imports are also referred to as delta imports. Use this guide to get started with the automatic CSV import using the CSV Import API. The examples provided in the instructions use the cURL command line.
The process of performing an automated CSV import in a nutshell.
POST
request to /users/imports/
.PATCH
request to /users/imports/{importId}/config/
.PATCH
request to /users/imports/{importId}
with state parameter set to PREVIEW_PENDING
.PATCH
request to /users/imports/{importId}
with state set to IMPORT_PENDING
in the request body.You can find examples of CSV files on our Support Portal.
Make a POST
request to the endpoint /users/imports
with the path of the CSV file in your local computer.
Example request
The following cURL command uploads a new CSV file from your local computer to your Staffbase platform.
Your CSV file is uploaded to the Staffbase platform. You can view it on the overview page of the Staffbase Studio.
In the response header, you can see the location URL of the imported file.
For example, https://exampleapp.staffbase.com/api/users/imports/660e76a12487882f89a095b4e
You can save the id from the response. In this case, 660e76a12487882f89a095b4e.
This id is the importId required for further steps.
Do the following to map the CSV attributes to the Staffbase Studio profile fields:
GET
request to the endpoint /users/imports
.importId
required in the next step.If there are multiple imports, you can identify the import you want based on the following parameters:
PATCH
request to the endpoint /users/imports/{importId}/config
, with the following details:Parameter | Description |
---|---|
delta | The parameter that defines if all users or only a subset of users should be included in the import.
|
encoding | The character encoding used in the CSV file.
|
generateRecoveryCode | The parameter that defines if recovery codes need to be generated or not.
If the CSV file includes recovery codes and the parameter generateRecoveryCode is also set to true, the recovery codes from the CSV file will be used. If the CSV file does not contain recovery codes, new ones will be generated. Also, you need to ensure that the recovery codes are correctly mapped to the property recoveryCode. |
reportMailAddress | The parameter to add a recipient email address for the processed CVS import report. |
reportOnlyErrors | The parameter that defines if an email only needs to be sent to the reportMailAddress recipient if an error occurs. |
sendMailsNew | The parameter that defines if invitation emails need to be sent to new users.
|
sendMailsPending | The parameter that defines if invitation emails need to be sent to pending users.
|
separator | The field separator used in the file to separate the values.
|
mapping | The parameter that holds the mapping between the CSV column and the respective profile field in the Staffbase platform. See CSV Import mappings. |
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. The example above shows this case.
See CSV Import error list to help you analyze your CSV import and get more information on potential warning and error codes.
After configuring the mapping, you can preview the file.
This is an optional step.
PATCH
request to the endpoint /users/imports/{importId}
, with state parameter set to PREVIEW_PENDING
.You get a 204 response.
GET
request to the endpoint /users/imports/{importId}/status
.You can view the changes that come with the import in the response.
Make a PATCH
request to the endpoint /users/imports/{importId}
, with state parameter set to IMPORT_PENDING
.
You can now schedule the imports and updates based on your business requirements using this CSV import workflow. 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.