Tag Archives: Service Desk Plus

Retrieve Ticket Information – Using Service Desk Plus REST API and PowerShell – Part 1 – Get_Request

Recently I was reading the article Service Desk Plus REST API. Well! yeah not really great for Automation at this point of time but partially served my needs.I love automation so thought of spinning up PowerShell to do few tasks which I perform on daily basis with minimum tool permission. Indeed, service desk plus has reporting feature and can be automated (Personally not interested to deep dive in it). Reporting automation in tool depends on the server hardware / software capacity and tool configuration. Consider Mid level managers and multiple technicians configured reporting for their needs we may fall in performance degradation. Many will do SQL query to pull reports. Do, remember after pulling reports we should work on Excel to make good reports.

What can we do with Service Desk Plus REST API?

  1. Request Operations [We will cover only this part in this blog!]
  2. Notes Related Operations
  3. Work log Related Operations
  4. Change Related Operations
  5. CMDB Related Operations
  6. Technician Related Operations

Let’s start Automating Reporting, to begin with ensure you have below perquisites

  1. Know about your server host name or URL of the tool and the port information – Eg: http://ServerName:<port>
  2. Keep the API documentation handy – we need to refer to this while coding.
  3. Contact your tool admin and get the API key – Do remember if you are a tool admin you can’t generate one for yourself with the same ID.

You can fetch Request Number by querying your SQL DB using PowerShell – Since, we have enough code in the internet we will skip the PowerShell code for retrieving inform from SQL DB.

My first attempt failed because I didn’t read the API documentation 🙂

REST_API1Ay! it’s doing something! grab the API documentation and follow the instructions. We need to post the operation name and we have got our API key already from tool admin!. Now use the PowerShell code like shown below

$Params = @{OPERATION_NAME=’GET_REQUEST’;TECHNICIAN_KEY=’ASK YOUR TOOL ADMIN’;}
$ticketid = ‘Get it manually for now’
$data = Invoke-RestMethod -Uri http://localhost:80/sdpapi/request/$ticketid/ -Method Post -Body $Params

Okay! This gave me what I need 🙂 🙂 🙂 XML 🙂 🙂 🙂

REST_API2

To retrieve the status information we need to see the response code like shown below

$data.API.response.operation.result

REST_API3

Okay! let us see the ticket information in PowerShell ISE 🙂 But! how do we know that information and status are in result and detail node? Simple, see the API documentation of Viewing Request – Example is shown in the below image

REST_API4Cool! We are good to fire the below PowerShell code.

$data.API.response.operation.Details.parameter

TaDa! The sample output is below

REST_API5

Service Desk Plus documentation time format is human readable format and this is not why? Well! I am not from manage engine team so I have no answer but as a System Admin I can read that as EPOCH time format. So, again do little more code in PowerShell and convert this time format.

“Date and Time Format is {0}” -f (([datetime]’1/1/1970′).AddSeconds([int](1439388404268 / 1000)))

REST_API6

So, I ended up converting it to Short Date String!

(([datetime]’1/1/1970′).AddSeconds([int](1439388404268  / 1000)).ToShortDateString())

That’s it for now, in next post we will see exporting multiple requests to XML for our automation demo! Enjoy PowerShell 🙂 🙂 🙂 🙂