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)" } } }