PowerShell script to create an incident using REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
# Define ServiceNow instance details
$instance = "https://dev080088.service-now.com"
$username = "itil.user"
$password = "password"
$table = "incident"
# Create the REST API endpoint
$uri = "$instance/api/now/table/$table"
# Create the incident payload
$body = @{
short_description = "4th Sep incident from PowerShell"
urgency = "2" # 1 - High, 2 - Medium, 3 - Low
impact = "2"
caller_id = "System Administrator" # Replace with a valid caller ID
} | ConvertTo-Json -Depth 3
# Create headers
$headers = @{
"Content-Type" = "application/json"
}
# Create credentials
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $securePassword)
# Submit the incident
try {
$response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body -Credential $creds
} catch {
Write-Error "API call failed: $_"
}
# Output the result
$response.result | Format-List