13 Replies Latest reply on May 26, 2020 3:06 PM by Stephen Ferrari

    Problem with passing parameters to create incident with REST API POST using Invoke-RestMethod in powershell script

    Stephen Ferrari
      Share This:

      This may be an easy challenge for seasoned powershell scripters.  I am using Remedy ITSM 9.104.002 and trying to create an incident via REST API POST using Invoke-RestMethod in a powershell script.  The errors I get back appear to be the way I formatted the body experience error. I have tried various syntax changes including :


      “ ‘values’ = @{…“ and “ values : @{…” and “$body = { values = @{…”  and I get errors similar to that in  post, https://communities.bmc.com/thread/190048. To run the script, I execute by passing in vales from the command line:


      PS C:\ > ./CreateIncident.ps1 "CREATE" "Baxter" "Bob" "This is the incident description" "1-Extensive/Widespread" "1-Critical"  "Direct Input" "User Service Restoration" "Calbro Services" "Bob"



      ## Set the variables from the parameters

      Param([string]$action,[string]$lastname, [string]$firstname, [string]$desc, [string]$impact, [string]$urgency, [string]$source, [string]$service, [string]$company, [string]$submitter)


      ##Get the token



      $body = @{

      values = @{

      z1D_Action = $action

      Last_Name = $lastname

      First_Name = $firstname

      Description = $desc

      Impact = $impact

      urgency = $urgency

      'Reported Source' = $source

      Service_Type = $service

      Company = $company

      Submitter = $submitter



      $UpdatedBody = ConvertTo-Json $body


      ## Create incident

      $response = Invoke-RestMethod 'http://csssstswvrem52.dev.local:8008/api/arsys/v1/entry/HPD:IncidentInterface_Create?fields=values(Incident Number)' -Method 'POST' -Headers $headers -Body $UpdatedBody


      ##Release the token


      When executing the script, I get the following:


      Invoke-RestMethod : [{"messageType":"ERROR","messageText":"Field ID specified is not found on this

      1. form.","messageAppendedText":"HPD:IncidentInterface_Create: ","messageNumber":311}]

      At C:\CreateIncident_v6.ps1:46 char:13

      + $response = Invoke-RestMethod 'http://<servername>:<port>/api/arsys/v1 ...

      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          + CategoryInfo: InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc eption

          + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand



      I tried adding -Content-Type 'application/json' to the Invoke-RestMethod when I create the incident but I believe the ConvertTo-Json statement will suffice.

      Any help is greatly appreciated.