-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_call.ps1
32 lines (25 loc) · 1008 Bytes
/
api_call.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Define the API endpoint URL
$apiUrl = "https://xxx.com/api/v2/job_templates/8/callback/"
$headers = @{
"Content-Type" = "application/json"
}
$body = @{
"host_config_key" = "demopass"
} | ConvertTo-Json
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
try {
# Make the API request (GET request in this example)
$response = Invoke-RestMethod -Uri $apiUrl -Method Post -Headers $headers -Body $body
# Check if the response is successful (HTTP status code 200)
if ($response.StatusCode -eq 200) {
# Process the API response here
Write-Host "API Response: $($response | ConvertTo-Json -Depth 4)"
} else {
# Handle non-200 status codes
Write-Host "API request failed with status code $($response.StatusCode)"
}
} catch {
# Handle any exceptions that may occur during the API request
Write-Host "An error occurred: $_"
}