Files
InstaClientPS/tools/autotask.ps1
Chris Payne 9109252f54 Force canada
2025-07-08 21:07:56 -04:00

56 lines
1.8 KiB
PowerShell

function Invoke-AutotaskProvision {
param (
[Parameter(Mandatory)]
[string]$CompanyName,
[Parameter(Mandatory)]
[string]$PhoneNumber,
[string]$Website,
[string]$Street,
[string]$City,
[string]$Province,
[string]$PostalCode,
[string]$Country, # Not used but accepted for compatibility
[Parameter(Mandatory)]
[hashtable]$Credentials
)
if (-not $Credentials["AutotaskURL"] -or
-not $Credentials["AutotaskIntCode"] -or
-not $Credentials["AutotaskUsername"] -or
-not $Credentials["AutotaskSecret"]) {
throw "Missing Autotask credentials in hashtable."
}
$BaseUrl = "https://$($Credentials["AutotaskURL"])/atservicesrest/v1.0/companies"
$Headers = @{
"ApiIntegrationcode" = $Credentials["AutotaskIntCode"]
"UserName" = $Credentials["AutotaskUsername"]
"Secret" = $Credentials["AutotaskSecret"]
"Content-Type" = "application/json"
}
$Body = @{
companyName = $CompanyName
companyType = 1
phone = $PhoneNumber
website = $Website
address1 = $Street
city = $City
state = $Province
postalCode = $PostalCode
countryID = 38 # Statically set to Canada
ownerResourceID = 4
} | ConvertTo-Json -Depth 3
try {
$Response = Invoke-RestMethod -Uri $BaseUrl -Method Post -Headers $Headers -Body $Body
return $Response.itemId, $Response.id, $Response.companyID, $Response.item.id | Where-Object { $_ } | Select-Object -First 1
} catch {
throw "[Autotask] Provisioning failed: $($_.Exception.Message)"
}
}