Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Create a change request from Azure DevOps via changecontrol api

sschlosser
Kilo Contributor

Hello
I keep getting bad request when trying to send in a change request.  Is my fields wrong?  I am new to this.

trigger: none

pool:
name: 'DevOps-Test'

steps:

- task: PowerShell@2
displayName: 'Create Change Control Request in ServiceNow'
inputs:
targetType: 'inline'
script: |


$serviceNowInstance = "<Service Now Instance>"
$apiEndpointChangeRequest = "/api/sn_devops/devops/orchestration/changeControl"
$url = "$serviceNowInstance$apiEndpointChangeRequest"

# Define the headers for the HTTP request
$headers = @{
"Content-Type" = "application/json"
"Accept" = "application/json"
"Authorization" = "sn_devops.DevOpsToken xxx:xxx"
}

 

# Define orchestration task details
$orchestrationTaskDetails = @{
message = "Pipeline execution started successfully"
triggerType = "user"
}

# Define the orchestrationTaskURL
$orchestrationTaskURL = "https://dev.azure.com/<organization name>/$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)"

# Build the change request payload
$changeRequestDetails =@{
attributes = @{
requested_by = @{
name = "<username>"
}
start_date = "2024-10-16 11:00:00"
end_date = "2024-10-20 11:00:00"
comments = "Creating a new change request via API"
category = "DevOps"
priority = "1"
callback_url = "https://dev.azure.com/<organization name>/<project name>/_apis/build/builds/$(Build.BuildId)?api-version=6.0"
orchestrationTaskDetails = $orchestrationTaskDetails
orchestrationTaskURL = $orchestrationTaskURL
}
} | ConvertTo-Json -Depth 10 -Compress
Write-Host "Change Request Payload: $changeRequestDetails"

try {
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $changeRequestDetails
Write-Host "Change Request Created Successfully!"
Write-Host "Response from ServiceNow: $($response | ConvertTo-Json -Depth 10)"
} catch {
Write-Error "Failed to create Change Request. Status Code: $($_.Exception.Response.StatusCode)"
Write-Error "Error Details: $($_.Exception.Message)"
}

0 REPLIES 0