Solved

powershell script with Rest API integration

  • 26 October 2022
  • 3 replies
  • 470 views

  • New SysMate
  • 0 replies

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.

icon

Best answer by CWCIT 16 November 2022, 17:33

View original

3 replies

Userlevel 5
Badge

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,

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.

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