Skip to main content

Bulk Update the Enrollment User (auth_username) using API

What

This problem and solution came from a customer who had many devices in FileWave, yet did not have the 'Enrollment User' (internally known as auth_username) populated. In order for automatic associations of iPads with Apple Classroom, devices must have an enrolment user set. While it’s possible to set these one by one, that does not scale well. Even hosted customers could benefit from this example.

When/Why

The below solution leverages the FileWave API and is a great example that any customer could build. You can run this script from your mac, Windows, or Linux computer, and it will talk to the API and make the changes in bulk.

This example happens to be a Python script.  As such, if ran on the FileWave Server, Python will already be installed.  However, for hosted customers, the script will not be ran on the server and it should be necessary to have Python installed on the device running this script

https://www.python.org/downloads/

https://docs.python.org/3/using/windows.html

How

  • The first step is to download the script:

    FileWave Download.png
  • Once downloaded, you will have athe zip filecontains containingtwo thefiles: bulk_change_device_authname.py script and an auth_username.csv file where your changes will be placed.

  • UnlessIf youthe arescript is not being ran directly on the server, it may be necessary to alter the first line of code, to specify the location of Python on the device running the scriptscript.  directlyFor example, on amacOS, CentOSthat ormay macOS based FileWave Server, you will need to edit the script’s first line to point at where Python is located on your system. In my case, on my macOS system, it wasbe:  #/usr/local/bin/python3 as I had installed Python from https://www.python.org/downloads/ This process should work on any OS that supports Python scripts, and on Windows, you can use the same URL to download Python for Windows. There is good documentation on using Python on Windows here: https://docs.python.org/3/using/windows.html

  • The nextCSV stepfile wouldshould be edited to editinclude the auth_username.csvdesired filelist of Devices with Users.  The supplied template looks like:

Device ID,Enrollment Username
67d6f4bfcf27fa62bb9815365c67ebf7fed8f9c3,test

An Inventory query could be used to containobtain the Device IDslist of the devices and the Enrollment User values you would like. Do not change the first row from “Device ID”IDs.  and “Enrollment Username” becauseNote, the script looksis atonly that.expecting Also,two docolumns notin addthe order of Device ID and Enrollment Username.

It may assists to initially export additional columns to assist with device identification, but after adding the CSV.usernames, Thebe best waysure to doremove this is to use FileWave to make a Queryany of yourthese devicesadditional andcolumns include Device ID as a field. Export that and then use something like Microsoft Excel to marryin the dataCSV with your list of Enrollment Users. Ultimately produce a file that has just the Device IDs and Enrollment Users.file.

bulk-update-api-query.png

  • TheObtain finalthe stepdesired isusers tobase64 lookApplication inToken yourfrom the FileWave AdminAdministrators forAssistant the Token you would need. Below is an image showing the Token in an example setup. Note that usually, in our examples, the base64 version of the token is used, but this script uses the Token itself. In my example, I used the user bob, but I made sure that the username had the required permissions to change custom field data. If you only have fwadmin then use that as that user will always have the needed permissions.view

api-key.png

YouThe canfollowing command may now runbe the below from Terminal.appexecuted on your mac or similarly on a WindowsmacOS or Linux system(a thatsimilar hascommand Python.could be executed on Windows) to action the process.

./bulk_change_device_authname.py --token {b5cb89a0-fe59-4cb1-9359-d72b79369c0} --host ExampleCo.filewave.net --mapping ./auth_username.csv

The script will give you feedback about the success or failure of any records.

Python Imports

The beginning of the script has a list of imports:

import argparse
import base64
import csv
import os
import re
import requests
import sys

If youany are missing, e.g 'requests', it should be necessary to instal them.  The script should report such an error if any are missing when ran.  Some are available on a default Python modulesetup.

like

It requests,is youpossible canto usuallyinstal easilyany addmissing.  itFor withexample, aon macOS or Linux, the command likemay belowappear andas note(depending that you should change the path to Python if it isn’t inupon the location below.of You’ll know that you are missing it because the script will give an error like requests not found.Python)

/usr/local/bin/python3 -m pip install requests

AtHopefully thisthe point, you should have success, and you should lookscript at this scriptpoint has been successful and can be see as a great example of how to do bulk actions using a CSV file against your FileWave server. This can easily be transformed into a script that does just about anything in bulk.actions.