Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-Request
  2. {
  3.     <#
  4.     .SYNOPSIS
  5.  This function is used to return a list of requests. If RequestID is specified then a single request is returned. If RequestID is ommited then all requests assigned to the specified filter are returned. The filter will default to All Requests if one is not specified.
  6.     .DESCRIPTION
  7.  Get a list of Requests
  8.     .EXAMPLE
  9.  Get-Request -SdpUri "http://sdp.domain.com" -ApiKey "1234567A-2AB0-12A3-A123-1234567890AB" -RequestID 1234
  10.     .PARAMETER RequestID
  11.     The RequestID is the integer assigned to a "ticket" automatically by service desk plus
  12.     .PARAMETER Filter
  13.     The Request View Filter. These filters can be created in SDP. To find the filter name, Click on the ADMIN tab in SDP. Under General Settings click API, and Documentation.
  14.  
  15.  In the new Tab click "Requests" then "View Requests Filters", then "Try now". This parameter accepts the VIEWID
  16.    
  17.     .PARAMETER ApiKey
  18.     This parameter is the API Key assigned to each technician. This serves as authentication to Service Desk Plus
  19.  
  20.  .PARAMETER Limit
  21.     This parameter limits the number of returned requests. the default is 50
  22.     .PARAMETER SdpUri
  23.     This is the URI for Service Desk Plus
  24.    
  25.     #>
  26.     [CmdletBinding()]
  27.     param
  28.     (
  29.         [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true, Position=0)]
  30.         [alias ("id")]
  31.         [Int32]
  32.         $RequestID=$null,
  33.         [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true, Position=1)]
  34.         [String]
  35.         $Filter = "All_Requests",
  36.         [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=2)]
  37.         [String]
  38.         $ApiKey,
  39.         [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=3)]
  40.         [String]
  41.         $SdpUri,
  42.         [Parameter(Mandatory=$false)]
  43.         [String]
  44.         $limit = 50
  45.     )
  46.     begin
  47.     {
  48.         if ($SdpUri[$SdpUri.Length -1] -eq "/") { $Uri = $SdpUri + "sdpapi/request" }
  49.         else { $Uri = $SdpUri + "/sdpapi/request" }
  50.     }
  51.     process
  52.     {
  53.         if ($RequestID -gt 0)
  54.         {
  55.             $Uri = $Uri + "/" + $RequestID
  56.             $Uri = $Uri + "?format=json&OPERATION_NAME=GET_REQUEST&TECHNICIAN_KEY=$ApiKey"
  57.             $result = Invoke-RestMethod -Method Get -Uri $Uri
  58.             $result
  59.         }
  60.         else
  61.         {
  62.             $Parameters = @{
  63.                 "operation" = @{
  64.                     "details" = @{
  65.                         "from" = "0";
  66.                         "limit" = $limit;
  67.                         "filterby" = $filter
  68.                     }
  69.                }
  70.             }
  71.        
  72.             $input_data = $Parameters | ConvertTo-Json -Depth 50
  73.             $Uri = $Uri + "?format=json&OPERATION_NAME=GET_REQUESTS&INPUT_DATA=$input_data&TECHNICIAN_KEY=$ApiKey"
  74.             $result = Invoke-RestMethod -Method Get -Uri $Uri
  75.             $result
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement