You can sync your Microsoft Active Directory Domain Services (AD DS) with the FacilityOS Address Book by running a script on your server.
Note:
This article uses a sample PowerShell script, but you can reference the information below to write your own script in any programming language.
Before you start
- Review the Security and confidentiality of data section.
-
Contact FacilityOS support to receive your API credentials. Your API credentials include your client ID and client secret.
Note:
If you need to sync multiple sites, you can request separate API keys to upload site-specific CSV files or include all records in a single CSV file by using the correct "Site" values when editing the data fields later in this article.
- If your Address Book already contains employees that were added manually, syncing with AD DS will not update their information. To ensure employee details are updated automatically, delete any manually added employees. To learn how, see Delete an employee.
Integrate the Address Book with AD DS
- Copy and paste the provided sample PowerShell script into a text editor, such as Windows Notepad.
- Save the script as a .ps1 file.
- Update the script as shown below. If you need help editing the script with your organization's information, contact your IT department.
-
AD search location: Update
$OULocation="OU=Users,DC=TOR"to your organization’s correct Organizational Unit (OU) and Domain Component (DC). -
API credentials: Locate
$client_id = 'Enter client ID here'and$client_secret = 'Enter client secret here', then enter the API credentials you received from FacilityOS support between the quotation marks. -
Data fields: Locate
$fields = @('Email Address','Full Name','Mobile Phone','HomePhone')and update the fields based on the user account properties your AD DS environment collects.Note:
To know which fields you can enter in your script, see the table in Data field mapping.
-
$urlDest parameter: If you have Gov Cloud, update
$urlDest = "https://partnerapi.goilobby.com/addressbook/uploadcsv";to$urlDest = "https://partnerapi.facilityos.us/addressbook/uploadcsv";. Otherwise, do not make changes to the parameter.
-
AD search location: Update
- Run the script on your server.
Sample PowerShell script for AD DS
The following sample script shows the general structure for exporting employee data from AD DS.
$OULocation="OU=Users,DC=TOR"
$client_id = 'Enter client ID here'
$client_secret = 'Enter client secret here'
$sourceFilePath = $PSScriptRoot + "\adextract.csv"
$fields = @('Email Address','Full Name','Mobile Phone','HomePhone')
Import-Module ActiveDirectory
$Users = Get-ADUser -Filter {Enabled -eq "True"} -SearchBase $OULocation -SearchScope Subtree -Properties $fields | select $fields
$Users | Export-Csv $sourceFilePath -NoTypeInformation -Force
$headers=@{}
$headers.Add("Content-Type", "application/x-www-form-urlencoded")
$response = Invoke-WebRequest -Uri 'https://partnerapi.goilobby.com/auth/connect/token' -Method POST -Headers $headers -Body "grant_type=client_credentials&client_id=$($client_id)&client_secret=$($client_secret)"
$token = ConvertFrom-Json $response.Content
$access_token = $token.access_token
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
$urlDest = "https://partnerapi.goilobby.com/addressbook/uploadcsv";
$webClient = New-Object System.Net.WebClient;
$webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
$webClient.Headers.Add("Authorization", "Bearer $($access_token)");
$resp = $webClient.UploadFile($urlDest, "POST", $sourceFilePath);
$enc = [System.Text.Encoding]::ASCII
$enc.GetString($resp)Data field mapping
The table below lists the names of the data fields your script can include.
| Data field name | Required | Description |
| FIRSTNAME | Yes | The employee's first name. |
| LASTNAME | Yes | The employee's last name. |
| TITLE | No | The employee's job title. |
| DIVISION | No | The employee’s team or division name. |
| Yes | The employee’s email address. This email address is used for email notifications. | |
| MOBILE | No | The employee’s mobile phone number. This number is used for SMS or voice notifications. |
| DESKPHONE | No | The employee’s primary office phone number. This number will also be used for SMS or voice notifications |
| SITE | No |
Sites where the employee can be visited. If blank, the employee will be assigned to all sites you have access to. Important: Make sure the site names in AD DS match those in FacilityOS. |
Verify the sync in FacilityOS
- In FacilityOS, from the left sidebar, click Manage, then select Address Book.
-
Successfully synced employees have a lock
icon. Select an employee to view details such as name, email address, phone number, and site assignment.
Important:
To edit an employee's details, make the changes in AD DS.