Skip to main content
Solved

powershell script with Rest API integration

  • October 26, 2022
  • 3 replies
  • 595 views

Does anyone have a working powershell script with Rest API integration. I am looking for a possibility to populate the solution field and the activity field from Powershell.

Best answer by CWCIT

Hello,

Here is a GIT that has some information to help with this.

https://github.com/kairood/SysAid-PowerShell-Automation/blob/master/SysAid_Authentication.ps1

 

I wrote some script to migrate our old system into SysAid (On-Prem) that utilized the API. I can share some of it if needed, once sanitized.

View original
Did this topic help you find an answer to your question?

3 replies

Maayan Karstaedt
SysAider
Forum|alt.badge.img

Hi @CCD 

From API perspective I can point you to: 

Solution field information & Activity fields available. 

and hopefully, other SysMates can point you in the right direction for PowerShell as we don’t use it ourselves. 

Cheers,


  • New SysMate
  • 4 replies
  • Answer
  • November 16, 2022

Hello,

Here is a GIT that has some information to help with this.

https://github.com/kairood/SysAid-PowerShell-Automation/blob/master/SysAid_Authentication.ps1

 

I wrote some script to migrate our old system into SysAid (On-Prem) that utilized the API. I can share some of it if needed, once sanitized.


  • New SysMate
  • 4 replies
  • November 16, 2022

Here is my SR update function as well, it may help you to build something.

function Add-SysAidAPIUpdateSR {
    <#
     .INPUTS
        ServiceUpdate, URI, WebSession, ID
     .PARAMETER ServiceUpdate - [STRING] should be a PSCustomObject Conterted to Json
     .PARAMETER URI/URL - SysAid URL/URI "http://mysysaid.domain.ca:8080/"
     .PARAMETER WebSession - Should be the session from the Get-SysAidAPIKey function
     .PARAMETER srID - INT32 id number of the Service Request to update
     .OUTPUTS
        PSCustomObject from returned SysAid Json. SysAid Example
     .EXAMPLE
        $returnedSR = Get-SysAidAPISR -ServiceRequest $SR -URI "http://mysysaid.domain.ca:8080/" -APIWebSession $webSession

        SysAid update json:  
        {
        "id":"273",
        "info": [{"key":"update_time", "value":1391756438000},
                    {"key":"status", "value":2},
                    {"key":"notes","value":[
                    {"userName":"sysaid","createDate":1391756438000,"text":"Note 123"}
                    ]},
                    {"responsibility":66}]
        }
     #>
     [CmdletBinding(DefaultParameterSetName="Default")]
     param (
         [Parameter(
             ParameterSetName="Default",
             Mandatory=$true,
             HelpMessage = "Web Session returned ay Get-SysAidAPIKey")]
         [Alias("API","JSESSIONID","Key","websession")]
         [ValidateNotNullOrEmpty()]
         [Microsoft.Powershell.Commands.WebRequestSession]$APIWebSession,
         [Parameter(
             ParameterSetName="Default",
             Mandatory=$true,
             HelpMessage = "Update to Service Request")]
         [Alias("update","ServiceRequestUpdate")]
         [ValidateNotNullOrEmpty()]
         [string]$srUpdate,
         [Parameter(
             ParameterSetName="Default",
             Mandatory=$true,
             HelpMessage="URL/URI for the SysAid Site http://[fqdn]:[port]/"
         )]
         [ValidateNotNullOrEmpty()]
         [Alias("URL","site")]
         [String]$URI,
         [Parameter(
             ParameterSetName="Default",
             Mandatory=$true,
             HelpMessage="ID - INT32 of the ticket to update"
         )]
         [ValidateNotNull()]
         [Alias("ID","serviceRequestID")]
         [Int32]$srID
     )

     begin{
         #Service Request URI's
         # $URISRUpdate="api/v1/sr/{0}"
         $finalURI= $URI + "api/v1/sr/" + $srID.ToString()
         #SysAid Time Conversion

         $Response = $null
         $functionError = $null
     }

     process{

         try {
             $Response = Invoke-RestMethod -Uri $finalURI -Method Put -ResponseHeadersVariable "responseHeaders" -WebSession $APIWebSession -ContentType 'application/json' -Body $srUpdate
         }
         catch {
             $functionError = $_
         }

     }

     end{
         if ($null -eq $functionError) {
             #$Response | ConvertTo-Json
             $Response
         }else{
             $functionError
         }
     }
}

 


Reply


Want Some cookies?

No, literally. We have some. 😉 By continuing browsing on our site you agree to our cookie policy.

 
Cookie settings