This is an example of creating a quick Node script for importing user data from a CSV and creating user accounts and licenses within Keygen.
This example application is not 100% production-ready, but it should get you 90% of the way there. You may need to add additional logging, error handling, license key and temporary password email delivery, etc.
First up, configure a few environment variables:
# Keygen product token (don't share this!)
export KEYGEN_PRODUCT_TOKEN="YOUR_KEYGEN_PRODUCT_TOKEN"
# Your Keygen account ID
export KEYGEN_ACCOUNT_ID="YOUR_KEYGEN_ACCOUNT_ID"
# The Keygen policy to use when creating licenses for new users
export KEYGEN_POLICY_ID="YOUR_KEYGEN_POLICY_ID"
You can either run each line above within your terminal session before
starting the app, or you can add the above contents to your ~/.bashrc
file and then run source ~/.bashrc
after saving the file.
Next, install dependencies with yarn
:
yarn
Then run the script to import the sample data from data/users.csv
:
yarn start
Reach out at support@keygen.sh if you have any questions or concerns!