How to Bulk Export Users and Quickly Filter the Dataset

Overview

This article demonstrates how to Bulk Export users and filter the resulting .csv file by last_login (for example) by using a command-line tool like Miller.

Example use case: We require a list of active users that have logged in since X date.

Applies To

  • Bulk User Export

Solution

1. Export the users to a .csv file.

a.

curl -L 'https://YOUR_DOMAIN/api/v2/jobs/users-exports' \

-H 'Content-Type: application/json' \

-H 'Accept: application/json' \

-H 'Authorization: Bearer MGMT_API_TOKEN' \

-d '{"format":"csv"}'

b.

curl -L 'https://YOUR_DOMAIN/api/v2/jobs/JOB_ID' \

-H 'Accept: application/json' \

-H 'Authorization: Bearer MGMT_API_TOKEN'

c. Navigate to the location URL to download the file.

d. (on Mac terminal)

cd ~/Downloads

gzip -d file.gz

2. Filter the users by last_login.

mlr --csv filter '$last_login >= "2024-01-01T00:00:00Z"' file.csv > filtered.csv