Hi,
are you using PowerShell to invoke the POST? Can you please share some more details on the approachg you are using?
Are you able to submit other requests or only the TaskSubmit is failing?
Regards,
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am testing out the SCOM REST API. I cannot seem to get the syntax correct for submittask. I get the error
"errorMessage":"An object of class ManagementPackTask with ID 00000000-0000-0000-0000-000000000000 was not found."
This is the content for the body
{
"taskId ": "569e7963-07be-3ecd-c061-93f155f58a5e",
"monitoringObjectIds": ["9be0fb2d-f4b8-54ee-370c-e7d7945fa244"],
"credentials": {
"username": "user",
"domain": "domain.com",
"password": "pass"
},
"parametersWithValues": {},
}
Has anyone had success getting the submittask to work with the SCOM REST API?
Hi,
are you using PowerShell to invoke the POST? Can you please share some more details on the approachg you are using?
Are you able to submit other requests or only the TaskSubmit is failing?
Regards,
I am using powershell to retrieve SCOM data via the rest API. I was successful in authenticating and retrieving alerts.
$scomHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$scomHeaders.Add('Content-Type','application/json; charset=utf-8')
$bodyraw = "Windows"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json
$uriBase = "http://<server>/OperationsManager/authenticate"
$CSRFtoken = $WebSession.Cookies.GetCookies($URIBase) | ? { $_.Name -eq 'SCOM-CSRF-TOKEN' }
$SCOMHeaders.Add('SCOM-CSRF-TOKEN', [System.Web.HttpUtility]::UrlDecode($CSRFtoken.Value))
$auth = Invoke-RestMethod -Method POST -Uri $uriBase -Headers $scomheaders -body $jsonbody -UseDefaultCredentials -SessionVariable websession
$query = @(@{ "classId"= ""
# Criteria output the critical new alerts
"criteria" = "((Severity = '2') AND (ResolutionState = ‘0’))"
"displayColumns" ="severity","monitoringobjectdisplayname","name","age","repeatcount","lastModified"
})
$jsonquery = $query | ConvertTo-Json
$Response = Invoke-RestMethod -Uri "http://<server>/OperationsManager/data/alert" -Method Post -Body $jsonquery -ContentType "application/json" -UseDefaultCredentials -WebSession $websession
$alerts = $Response.Rows
$test = @"
{
"taskId ": "569e7963-07be-3ecd-c061-93f155f58a5e",
"monitoringObjectIds": ["9be0fb2d-f4b8-54ee-370c-e7d7945fa244"],
"credentials": {
"username": "xxxxx",
"domain": "xxxxxx",
"password": "xxxxxx"
},
"parametersWithValues": {},
}
"@
$URI="http://server/OperationsManager/data/submitTask"
Invoke-RestMethod -Uri $URI -Method Post -Body $test -ContentType "application/json" -UseDefaultCredentials -WebSession $websession
This produces the following error.
Invoke-RestMethod : {"errorMessage":"An object of class ManagementPackTask with ID 00000000-0000-0000-0000-000000000000 was not found.","errorTrace":" at
Microsoft.EnterpriseManagement.TaskConfigurationManagement.GetTask(Guid id)\r\n at
Microsoft.EnterpriseManagement.OMDataService.Service.Impl.Data.TaskData.GetTaskById(Guid taskId)\r\n at
Microsoft.EnterpriseManagement.OMDataService.Service.Impl.Data.TaskData.SubmitTaskForExecution(Guid taskId, List1 monitoringObjectIds, Dictionary
2
parametersWithValues, TaskExecutionCredentials credentials*
The task id is valid. I do not understand why the REST call thinks the task id is all zeros.