Home Powershell

Creating IR with powershell and CloudConnector API

Patrick_AigelsrPatrick_Aigelsr Member IT Monkey ✭

Hi everyone!

I am trying to create a Incident Ticket with CloudConnector API and basically it works as long as I do not try to also set the affected user or an assigned user.

I even tried to first create the WorkItem and then Update it but it also fails with the same error message:

The given key was not present in the dictionary.

This is my code:

$AssigneeUser = "SamAccountName1"
$AffectedUser = "SamAccountName2" $AssigneeUserDb = $(Invoke-Sqlcmd -ServerInstance "MYDBSERVER" -Database "ServiceManagement" -Query "EXEC spGet_UserByUserName '$AssigneeUser'" -TrustServerCertificate) $AffectedUserDb = $(Invoke-Sqlcmd -ServerInstance "MYDBSERVER" -Database "ServiceManagement" -Query "EXEC spGet_UserByUserName '$AffectedUser'" -TrustServerCertificate) $AssigneeBaseID = $AssigneeUserDb.Id.guid
$AffectedUserBaseID = $AffectedUserDb.Id.guid $IRCreatebody = @{
"ClassTypeId" = "a604b942-4c7b-2fb2-28dc-61dc6f465c68" # Incident Class ID
"Classification" = @{ "Id" = $ClassificationBaseID }
"Impact" = @{ "Id" = "8F1A713E-53AA-9D8A-31B9-A9540074F305" } # Me
"Urgency" = @{ "Id" = "02625C30-08C6-4181-B2ED-222FA473280E" } # Medium
"Title" = $Title
"Description" = $Description
"RequestedWorkItem" = @{ "BaseId" = $AffectedUserBaseID } # Affected User
"AssignedWorkItem" = @{ "BaseId" = $AssigneeBaseID } # Assigned User
"TierQueue" = @{ "Id" = $($($SupportGroups | Where-Object { $_.DisplayString -eq $SupportGroup}).EnumerationID.Guid) }
"Source" = @{ "Id" = "615778D5-485A-752F-3C5D-F412F806E624" }
"Status" = @{ "Id" = "5e2d3932-ca6d-1515-7310-6f58584df73e" }
} | ConvertTo-Json

$createUrl = "https://gissc.intranet.zkw.at/api/CloudConnector/WorkItems"
$WorkItem = Invoke-RestMethod -Uri $createURL -Method "POST" -Headers @{"Authorization"="$platformToken"} -ContentType "application/json" -body $IRCreatebody

If I remove the "RequestedWorkItem" and "AssignedWorkItem" it is working.
In the Article KB 2603 from Cireson Knowledge in Example 4 it is shown like I did for the "AssignedWorkItem".

I also tried if the GUID's for for those are found in CI$User and they are. They have to, since spGet_UserByUserName gets the Id's from this table.

I really hope someone can help me with that. I am aware that I could do the same using MS Orchestrator or Power Automate but I need to avoid that.

Best regards, Patrick

Answers

  • Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    edited September 5

    This is really a downside of the cloud connector imo - It is not possible to create relationships on creation.
    Based on the timespan from creation to finally being able to add the relationship, it seems the relationship can be set as soon as the cachebuilder has grabbed the work item.

    A colleague of mine and me created a logic app in Power Automate, he built the workflow and I built the JSONs he had to build in order to send it to the cloud connector API. Right now after creation it contains an iteration, which tries to set relationships until it finally works. This leads to lots of error messages in the webconsole log file, as it always states, that the workitem with the ID has not been found. In general for us this is suboptimal and it would be really fine if we could create relationships during creation.

Sign In or Register to comment.