Quantcast
Channel: Support Portal
Viewing all articles
Browse latest Browse all 20315

ServiceDesk Plus API - Filtering Requests

$
0
0
This question has been posing a few issues recently but a number of clients have been attempting to return a list of requests via the API by a specific value on the Request such as Group. As with a lot of these things its pretty simple but not immediately obvious if you don't know where to look for the information.

First off you might want to download our API white paper which sets the groundwork for using the API interface in ServiceDesk Plus:


If you're confident with the content of the white paper lets review the API interface operations we'll need to get a list of requests (you can locate this in the API documentation under Admin - General Settings - API in the GUI of ServiceDesk Plus).

The first operation we are interested in is 'View All Requests' as shown from the API documentation below:
















The operation has a few controls of interest namely 'from', 'limit' and 'filterby'. Now the first two are hopefully reasonably self-explanatory as the starting point in a filtered list of requests and the maximum number of requests to return from the starting point in that filtered list of requests. 

The key point to take away here is that it is a filtered list of requests. Once you realise this it opens up a raft of possibilities as you can even use your own custom filters to return a list of requests. 

Now the catch. Try as you might to replace the 'filterby' option with the name of your filter in ServiceDesk Plus it never seem to work as intended. This is where you need a second operation, 'View Request Filters', from the API to determine the 'View ID' of the filter you want to apply to the returned list of requests:










Once you've determined the 'View ID', and this includes any Group filters you may have set for the Technician account you're using the API key for, you can substitute this in the 'filterby' control of the 'View All Requests' operation.

To help you out I've included an example PowerShell script that searches for a custom Group I've created in my test system of 'Case Management' (for simplicity you can easily test this script in the PowerShell ISE editor replacing the URL, technician key and 'filterby' elements). 

 # Set system parameters - change these details to suit your system environment
$sdphost = "http://localhost:8888/" 
$techkey = "83460559-E959-4525-B17A-209D2AE698F0"

# Set API module URL and operation
# This is the URL for calling the Request API in order to Reply to a Request # It users the Request ID as a parameter
# It uses the request parameter passed to the script $workorderid
$url = $sdphost + "sdpapi/request/"
$method = "POST"
$operation = "GET_REQUESTS"

# Configure input data for email Reply operation in JSON format
$inputdata = @" 
{
    "operation": {
        "details": {
            "from": "0",
            "limit": "10",
            "filterby": "Case Management_QUEUE"
        }
    }
"@

# Configure paramaters for web API call as an array of object and format as JSON data.
# This is a more elegant method than creating a text string to build the URL
$params = @{INPUT_DATA=$inputdata;OPERATION_NAME=$operation;TECHNICIAN_KEY= $techkey;format='json'}
# Make a web API call and record result
$response = Invoke-WebRequest -Uri $url -Method POST -Body $params

# Output Result
write-host $response 

In the example you'll see the 'View ID' of the Group 'Case Management' is in fact, 'Case Management_QUEUE' ...... right. of course!

Hope this helps.

set3 Solutions

Viewing all articles
Browse latest Browse all 20315

Trending Articles