CSM 10.5 Documentation

Home

PowerShell Example: Delete A Business Object

The following example shows how to delete a Business Object using PowerShell.

                        # Set server login variables
$serverName = "your server"
$apiKey = "your client id"
$userName = "CSDAdmin"
$password = "CSDAdmin"
$baseUri = "https://${serverName}/CherwellAPI/"

# Get an access token
$tokenUri = $baseUri + "token"
$authMode = "Internal"
$tokenRequestBody =
@{
    "Accept" = "application/json";
    "grant_type" = "password";
    "client_id" = $apiKey;
    "username" = $userName;
    "password"= $password
}
$tokenResponse = Invoke-RestMethod -Method POST -Uri "${tokenUri}?auth_mode=${authMode}&api_key=${apiKey}" -Body $tokenRequestBody

$requestHeader = @{ Authorization = "Bearer $($tokenResponse.access_token)" }

# Get the business object summary for Incident. This will give us the busObId
$summaryUri = $baseUri + "api/V1/getbusinessobjectsummary/busobname/Incident"
$summaryResults = Invoke-RestMethod -Method GET -Uri $summaryUri -ContentType application/json -Header $requestHeader
$busObId = $summaryResults[0].busobId

# Delete business object
$deleteIncidentUri = $baseUri + "api/V1/deletebusinessobject/busobid/${busobid}/publicid/102522"
$deleteIncidentResponse = Invoke-RestMethod -Method DELETE -Uri $deleteIncidentUri -ContentType application/json -Header $requestHeader
                    

Was this article useful?