Hey there,
I am by no means the most organized PowerShell person, but I have successfully gotten this working by reading a csv file for my website names. Additionally I have put the API credential and header work into a function and I call that when you see send-request.
CSV Example
google.com
amazon.com
$websites = Import-Csv -Path "PUT YOUR FILE PATH HERE" header name
$resourcePath = "/website/websites/"
$queryParams = ""
# Loop through each website and create a new website with the given request body
$i=0
foreach ($website in $websites){
$data='{
"type": "webcheck",
"domain": "' + $websites[$i].name + '",
"testLocation": {
"smgIds": [2, 3, 4]
},
"name": "' + $websites[$i].name + '",
"steps": [
{
"url": "' + $websites[$i].name + '",
"timeout": 120
}
]
}'
#Main Client Group
#$data='{"type":"webcheck","domain":"' + $websites[$i].name + '","testLocation":{"smgIds":[2, 3, 4]},"name":"' + $websites[$i].name + '","steps":[{"url":"' + $websites[$i].name + '","timeout":120}]}'
$results = Send-Request $resourcePath $httpVerb $queryParams $data
write-host $data
Write-Host $results
$i = $i + 1
}
Also, for website groups I use this:
$CsvFilePath = "C:\Temp\SiteCodes.txt"
# Read the CSV file
$SiteCodes = Import-Csv -Path $CsvFilePath -header siteCode
$resourcePath = '/dashboard/groups/'
# Loop through the site codes and create dashboard groups
foreach ($SiteCode in $SiteCodes) {
# Build the JSON request body
$data = @{
name = "$($SiteCode.siteCode) Dashboard Group"
} | ConvertTo-Json
# Send the API request to create the dashboard group
$Response = send-request -resourcePath $resourcePath -httpVerb POST -data $data
# Print the response to the console
Write-Output "Dashboard group created: $($Response.name)"
}
Maybe this helps and maybe not but figured I would share what worked for me.