Skip to content

Commit

Permalink
Add Staff examples (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsquidwrd authored Mar 8, 2024
1 parent 841548e commit da09c28
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Examples/Staff/Update_Staff_Module.ps1
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
43 changes: 43 additions & 0 deletions Examples/Staff/Update_Staff_NonModule.ps1
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 $_
}
}
4 changes: 4 additions & 0 deletions Examples/Staff/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Url": "https://demo.aeries.net/aeries/",
"Certificate": "477abe9e7d27439681d62f4e0de1f5e1"
}

0 comments on commit da09c28

Please sign in to comment.