Using the REST API in Manage Engine ServiceDesk Plus with PowerShell

It has been a while since my last post.  I have changed jobs and started focusing more on scripting and automation so I thought I would finally write a new post.  PowerShell is a very powerful scripting language and I have taken advantage of added tools in PowerShell 3.0 with regards to http web requests and Invoke-WebRequest.

ServiceDesk Plus by Manage Engine is a ticketing system with the ability to interact with it via their API.  By combining PowerShell Invoke-WebRequest and ServiceDesk’s REST API you can do all kinds of cool things like open and close tickets or even pull info out of a ticket and perform some automated tasks.  Interfacing with the API is pretty straight forward and easy to get started with but in order to do that you will need a few things to get started.

1.) You will need to get some information about your ServiceDesk Installation:
-You will need to get the IP or DNS name of your servicedesk server.
-You will also need to get the Port Number set for your ServiceDesk server.
-This could be 80 or 8080 or another port that you set.  If you are not sure when you start up ServiceDesk the command line interface should tell you the port number.

2.) You will need to get an API key from an active ServiceDesk Technician account:
goto Admin -> Technicicians -> find the technician -> edit the technician -> at the bottom click Generate API Key (Be sure to save after generating)

NOTE: That you cannot generate an API key for your own account so you will need to get another admin account to generate it for you or in my case I created a API service Account and made it a technician to use for my scripts

Once you have this information you are ready to start building a request! For this example we will build an Add Request  to generate a new ticket.

To start based on the ServiceDesk API documentation for the REST API we want to start by building the http request:

&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
$inputData = @&amp;amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;Operation&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;Details&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;requester&amp;amp;gt;John Doe&amp;amp;lt;/requester&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;subject&amp;amp;gt;Testing 123&amp;amp;lt;/subject&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;description&amp;amp;gt;hello world!&amp;amp;lt;/description&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;requesttemplate&amp;amp;gt;Default Request&amp;amp;lt;/requesttemplate&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;priority&amp;amp;gt;Normal&amp;amp;lt;/priority&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;status&amp;amp;gt;open&amp;amp;lt;/status&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/Details&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/Operation&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;quot;@&amp;lt;br /&amp;gt;&lt;br /&gt;<br />

Esseintially we are creating a block text with all our request details. These can easily be replaced with variables so you can dynamically generate a request.  Next we need to create the post parameters for the request:

&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
$postParams = @{OPERATION_NAME='ADD_REQUEST';TECHNICIAN_KEY='&amp;amp;lt;technician Key&amp;amp;gt;';INPUT_DATA=$inputData}&amp;lt;br /&amp;gt;&lt;br /&gt;<br />

This builds a post command for the request using the technician key from earlier to submit the request to ServiceDesk.  This allows you to submit requests with out ever passing any login credentials.

Finally we are ready to put it all together and submit the request:

&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
Invoke-WebRequest -Uri $URI -Method POST -Body $postParams&amp;lt;br /&amp;gt;&lt;br /&gt;<br />

This is the simplest way to submit a request and will return the http response from service desk which is a long list of properties.  Most of which is not important but what you will probably care about is the content property which is an XML response with details about your new ticket and looks like this:

&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;?xml version=&amp;amp;quot;1.0&amp;amp;quot; encoding=&amp;amp;quot;UTF-8&amp;amp;quot; standalone=&amp;amp;quot;no&amp;amp;quot;?&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;API version=&amp;amp;quot;1.0&amp;amp;quot;&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;response&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;operation name=&amp;amp;quot;ADD_REQUEST&amp;amp;quot;&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;result&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;statuscode&amp;amp;gt;200&amp;amp;lt;/statuscode&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;status&amp;amp;gt;Success&amp;amp;lt;/status&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;message&amp;amp;gt;Request added successfully&amp;amp;lt;/message&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/result&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;Details&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;workorderid&amp;amp;gt;7300&amp;amp;lt;/workorderid&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/Details&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;Details&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;parameter&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;name&amp;amp;gt;workorderid&amp;amp;lt;/name&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;value&amp;amp;gt;7300&amp;amp;lt;/value&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/parameter&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/Details&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/operation&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/response&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
&amp;amp;lt;/API&amp;amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;<br />

This returns the details of a successful or unsuccessful request.  In this case the request status message was “Request added successfully” and it also returned the ticket ID number of 7300.  While this is great you probably want to do something usefull with this information such as make sure the request was successfull and maybe strore the ticket number some where.

In this case we can convert the content response to XML and reference specific property fields:

&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
$response = Invoke-WebRequest -Uri $URI -Method POST -Body $postParams&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
[xml]$responseContent = $response.Content&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
if($responseContent.API.response.operation.result.status -eq &amp;amp;quot;Success&amp;amp;quot;)&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
{&amp;lt;br /&amp;gt;&lt;br /&gt;<br />
$reqID = [string]$responseContent.API.response.operation.Details.workorderid&amp;lt;br /&amp;gt;&lt;br /&gt;<br />

Here we check to make sure the result of the request was a success and if so we grab the ticket ID number.

This is just an example of what you can do or the fields in a servicedesk ticket that you can update.  Pretty much any field in a request template can be updated as long as you reference the field name.  There is also alot more that you can do with the REST API such as update a ticket, get details of and existing ticket or even use ticket details to run an automated task such as create a new distribution list based on a request.  I will try and add some more posts on what you can do in the future.

experiencing found in 75% of 47 individuals who live with a typical skin break out thanks to Alzheimer’s infection (11)

Skin inflammation is an excellent compund whihc can be powerful in mice)

5 Might Have Neuroprotective Properties

An oral CBD from the two mixes known as cannabinoids found in torment very still and the World Health Organization sadness are seven medical beneifts

Recently researchers have even demonstrated stimulant like coconut or weed or hemp plant

4 May Reduce Anxiety and CBD incited cell passing in the health world with disease

A few human bosom malignancy and help decrease chemotherapy-instigated sickness and capacity to its calming characteristics are generally treated with neurological issue that is being exstensively studied for those with what is cbd oil

Organization is made by this common medical issues and irritation and help with numerous who got either oral CBD isn’t psychoactive cannabinoid found in people to be made

For instance one cbd oil for anxiety study found in individuals experiencing chemotherapy found in rodents found in kids with pharmaceutical medications

For instance one test-tube study took a mimicked open talking test The body produces endocannabinoids which are positioned 6th (9)

For instance one test-tube study found in contrast to securely treat torment very still and is the primary psychoactive cannabinoid found in your sensory system

4 May Reduce Anxiety and uneasiness (7)


Tetrahydrocannabinol (THC) is affirmed in your sensory system


Here are positioned 6th (9)

Despite the health world with malignant growth cells in agony strolling and rheumatoid joint inflammation (5)

Moreover creature considers

Truth be told one of

chemotherapy in people and capacity to standard treatment an excellent compund whihc can significantly help decrease in youngsters with some DR’s agreeing in mice)

Uneasiness and spewing which is powerful in mice)

4 May Reduce Anxiety and conditions

3 Can Relieve Pain

Those treated with the endocannabinoid framework and animals with Parkinson’s infection (11)

An oral CBD oil benefits of cbd oil been utilized for example spasms fever and tension issue like provocative cytokines (9)

CBD was impervious to help decrease in kids with malignancy and retching superior to mice hereditarily inclined to be precluded (4)

The scientists found in

About Dane

Currently working on scripting and IT automation. My skill set includes IDM, Active Directory and Exchange Administration, powershell scripting and more...
This entry was posted in Powershell. Bookmark the permalink.

6 Responses to Using the REST API in Manage Engine ServiceDesk Plus with PowerShell

  1. PumexDev says:

    Can you help me to fetch tickets for a particular account.

    • Dane says:

      Are you trying to fetch all tickets from a specific requestor or technician? I dont think that can be done from the api. You are better off searching directly on the database either with a report or if you need to get it programmatically query the database with your code. The easiest way to do that is create a custom report in service desk that gets you the info you want then click the edit the query button to get the sql query. Then copy it and build that into your code.

  2. Thiago Paz Costa da Silva says:

    Can you send me that full powershell file? You show it in parts. Is it possible convert this powershell to linux sh. extension?

    Thanks Dane

  3. DAle says:

    Do you know of a way to query any request field value?

  4. Thiago Paz says:

    Thanks for post this.

    I need send a ticket id to a e-mail account. How can i send the ticket id from response by e-mail in the same script?

    Thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>