-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
try { Stop-Transcript } catch {} | ||
Start-Transcript -Path (Join-Path -Path $PSScriptRoot -ChildPath "log.txt") | ||
|
||
Import-Module -Name AeriesApi | ||
|
||
$ConfigFile = (Join-Path -Path $PSScriptRoot -ChildPath "config.json") | ||
$Config = (Get-Content -Path $ConfigFile | ConvertFrom-Json) | ||
|
||
$DataDirectory = ($PSScriptRoot) | ||
$DataFile = (Join-Path -Path $DataDirectory -ChildPath "staff.csv") | ||
$StaffData = (Get-Content -Path $DataFile | ConvertFrom-Csv) | ||
|
||
Initialize-AeriesApi -URL $Config.Url -Certificate $Config.Certificate | ||
$AeriesStaff = (Get-AeriesStaff) | ||
# $NewID, $AvailableIDs = (1..5000 | Where-Object { $_ -notin $AeriesStaff."ID" }) | ||
|
||
foreach ($Staff in $StaffData) { | ||
$AeriesRecord = ($AeriesStaff | Where-Object -Property "HumanResourcesSystemID" -EQ $Staff."id" | Select-Object -First 1) | ||
|
||
<# | ||
Map from File to Parameters | ||
Left: Parameter Name | ||
Right: File Value | ||
#> | ||
$StaffInformation = @{ | ||
"HumanResourcesSystemID" = $Staff."id" | ||
} | ||
|
||
<# | ||
If no existing Staff record exists, create one | ||
otherwise update the existing one | ||
#> | ||
if ([string]::IsNullOrEmpty($AeriesRecord."ID")) { | ||
# $StaffInformation."StaffID" = $NewID | ||
$AeriesRecord = (Add-AeriesStaff @StaffInformation) | ||
|
||
# $NewID, $AvailableIds = $AvailableIds | ||
} | ||
else { | ||
$AeriesRecord = (Edit-AeriesStaff -StaffID $AeriesRecord."ID" @StaffInformation) | ||
} | ||
} | ||
|
||
Stop-Transcript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$Url = "https://demo.aeries.net/aeries" | ||
$Cert = "477abe9e7d27439681d62f4e0de1f5e1" | ||
|
||
$Headers = @{ | ||
"AERIES-CERT" = $Cert | ||
} | ||
|
||
$ExistingStaff = (Invoke-WebRequest -Uri "$($Url)/api/v5/staff" -Headers $Headers).Content | ConvertFrom-Json | ||
|
||
$StaffData = (Get-Content -Path "./staff.csv" | ConvertFrom-Csv) | ||
|
||
foreach ($StaffCSV in $StaffData) { | ||
$ExistingStaffRecord = ($ExistingStaff | Where-Object -Property "HumanResourcesSystemID" -EQ $StaffCSV."id") | ||
|
||
$StaffPayload = @{ | ||
"HumanResourcesSystemID" = $StaffCSV."id" | ||
"FirstName" = $StaffCSV."first_name" | ||
"LastName" = $StaffCSV."last_name" | ||
"EmailAddress" = $StaffCSV."email" | ||
"Address" = $StaffCSV."address" | ||
"AddressState" = $StaffCSV."state" | ||
"AddressCity" = $StaffCSV."city" | ||
"AddressZipCode" = $StaffCSV."postal_code" | ||
} | ||
|
||
if ($ExistingStaffRecord) { | ||
# Update | ||
$RequestUrl = "$($Url)/api/v5/staff/$($ExistingStaffRecord."ID")" | ||
$Method = "PUT" | ||
} | ||
else { | ||
# Create | ||
$RequestUrl = "$($Url)/api/v5/staff" | ||
$Method = "POST" | ||
} | ||
|
||
try { | ||
Invoke-WebRequest -Method $Method -Uri $RequestUrl -Headers $Headers -Body $StaffPayload | ||
} | ||
catch { | ||
Write-Error $_ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"Url": "https://demo.aeries.net/aeries/", | ||
"Certificate": "477abe9e7d27439681d62f4e0de1f5e1" | ||
} |