2 Replies Latest reply on May 14, 2018 10:12 PM by lworman

    Powershell to bulk create new tickets in Webhelpdesk (WHD)

    lworman

      I'm trying to write a powershell script that will take in a list of Asset tags, and generate individual work orders for each of the assets.

      So far I've been able to get the following written:

      $ListOfAssests = get-content "ListOfAssets.txt"

      Foreach ($AssetID in $ListOfAssets)

      {

           # Get the WebHelpDesk ID for the Asset

           $WHDID = invoke-restmethod -Uri "http://webhelpdesk:8081/helpdesk/WebObjects/Helpdesk.woa/ra/Assets/?assetNumber=$AssetID&apiKey=<apikey>"

           write-host "The WebHelpDesk ID for Asset $AssetID = $WHDID"

       

           # Create JSON for work order for the Asset

           $JSon = [ordered]@{subject="";detail="Work order for $AssetID";problemType=[ordered]@{type="RequestType";id=2}}

           $JSon += [ordered]@{statustype=[ordered]@{type="StatusType";id=2};priorityType=[ordered]@{type="PriorityType";id=3}}

           $JSon += [ordered]@{assets=[ordered]@{type="Asset";id=$WHDID}}

       

           $JSon | convertTo-JSon -Depty 10 | set-content "$AssetID-JSonFile.json"

       

           # Post Work Order

           invoke-restmethod -Infile "$AssetID-JSonFile.json" -Method POST -Uri "http://webhelpdesk:8081/helpdesk/WebObjects/Helpdesk.woa/ra/Tickets?apiKey=<apikey>"

       

      }

       

      In my test I have just one asset in the file, so it does not loop too much.

       

      The problem is that at the Post Work Order part I get the following error:

      Invoke-RestMethod : ERROR: Must provide a request type.

       

      I cannot find anything that tells me where the "Request Type" must be specified in the JSon in order for this to work, other than in the "probemType" field.

      I've looked all through out the following document, but cannot find anything in regards to setting the Request Type for a new ticket:
      Web Help Desk REST API Guide

       

      Things I have tried, but to no success:
      * Put all the JSon parts on one line, I broke it into multiple lines to help make it readable

      * removed the [ordered] parts

      * used 'problemType=@{type="ProblemType";id=2}' in place of 'problemType=@{type="RequestType";id=2}'

      * used 'requestType=@{type="ProblemType";id=2}' in place of 'problemType=@{type="RequestType";id=2}'

      * I've been able to look at the values for other work orders in the system using the invoke-restmethod and see that they all return a similar value to

      'problemType : @{id=2; type=RequestType ; detailDsiplayName=fix}