From fa18f7a3d48555289ac752acaf9adbc9e6f43d1a Mon Sep 17 00:00:00 2001 From: Chris Payne Date: Tue, 8 Jul 2025 22:03:13 -0400 Subject: [PATCH] Implement ITG API --- main.ps1 | 7 +++++++ tools/itglue.ps1 | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tools/itglue.ps1 diff --git a/main.ps1 b/main.ps1 index 194b240..01577b5 100644 --- a/main.ps1 +++ b/main.ps1 @@ -19,6 +19,7 @@ $urls = @{ autotask = "https://git.svstools.com/cpayne/InstaClientPS/raw/branch/main/tools/autotask.ps1" datto = "https://git.svstools.com/cpayne/InstaClientPS/raw/branch/main/tools/dattormm.ps1" pax8 = "https://git.svstools.com/cpayne/InstaClientPS/raw/branch/main/tools/pax8.ps1" + itglue = "https://git.svstools.com/cpayne/InstaClientPS/raw/branch/main/tools/itglue.ps1" config = "https://git.svstools.com/cpayne/InstaClientPS/raw/branch/main/config.ps1" } @@ -264,6 +265,12 @@ $SubmitBtn.Add_Click({ -Credentials $script:toolCredentials } + if ($ITGlueBox.IsChecked) { + Write-Host "[INFO] Provisioning IT Glue..." + Invoke-ITGlueProvision -CompanyName $company -Credentials $script:toolCredentials + } + + $StatusBlock.Text = "Provisioning completed successfully." Write-Host "[SUCCESS] Provisioning complete." diff --git a/tools/itglue.ps1 b/tools/itglue.ps1 new file mode 100644 index 0000000..ac44a64 --- /dev/null +++ b/tools/itglue.ps1 @@ -0,0 +1,41 @@ +function Invoke-ITGlueProvision { + param ( + [Parameter(Mandatory = $true)] + [string]$CompanyName, + + [Parameter(Mandatory = $true)] + [hashtable]$Credentials + ) + + if (-not $Credentials.ITGUrl -or -not $Credentials.ITGKey) { + Write-Host "[WARN] Missing ITGUrl or ITGKey in credentials. Skipping IT Glue provisioning." + return + } + + $headers = @{ + "x-api-key" = $Credentials.ITGKey + "Content-Type" = "application/vnd.api+json" + } + + $body = @{ + data = @{ + type = "organizations" + attributes = @{ + name = $CompanyName + } + } + } | ConvertTo-Json -Depth 10 + + try { + $response = Invoke-RestMethod -Uri "$($Credentials.ITGUrl)/organizations" -Method POST -Headers $headers -Body $body + Write-Host "[INFO] Created IT Glue org: $($response.data.attributes.name)" + } + catch { + if ($_.Exception.Response.StatusCode.Value__ -eq 422) { + Write-Warning "[WARN] IT Glue org may already exist: $CompanyName" + } + else { + Write-Error "[ERROR] IT Glue provisioning failed: $($_.Exception.Message)" + } + } +}