Create a Ticket in Autotask using Powershell

UPDATE: I have published an updated version of this article based on our new PowerShell module for Autotask.

Once you have connected Powershell to Autotask (see my previous post for a howto), you can query, create and update everything that the API allows. In this post I will show you how to create a new ticket, but the method is the same for all entities.

Powershell makes it very easy to work with SOAPbased APIs. When you create a new WebServiceProxy object i Powershell it will read and import all definitions that the API provider has posted in the WSDL resource. This includes all entities, properties and methods. So to create a new ticket the basic steps are:

$Ticket = New-Object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1k_net_atservices_1_5_atws_wsdl.Ticket

$Ticket.AccountID = 0 # The internal account for test. Required.
$Ticket.DueDateTime = '2015-12-31' # Any date. Required.
$Ticket.Priority = 2 # Medium. Required.
$Ticket.Status = 1 # New. Required
$Ticket.QueueId = 12345678 # Your Queue IDs are unique 
$Ticket.Title = 'Ticket title for a test ticket'

$Result = $atws.create($Ticket)

The hardest part, or at least the part that will be most time consuming, is to figure out which AccountId, Status and QueueId to use. This really depends on what you want to automate. If all tickets are to be created against the same account you can just copy the AccountId from the Autotask Web interface. But in most cases it would be useful to be able to determine this programmatically. To do it by Account Name you can do use my QueryXML function:

$QueryXML = New-AtwsQuery account accountname equals 'ACME Inc.'
$Result = $Atws.query($QueryXML)
$AccountId = $Result.EntityResults[0].accountid

Perhaps more interesting would be to do it by contact email address:

$email = '[email protected]'
$QueryXML = New-AtwsQuery contact emailaddress equals $email
$Result = $Atws.query($QueryXML)
$AccountId = $Result.EntityResults[0].accountid

GetFieldInfo()

For QueueId you will need more information from Autotask. If you check the API documentation (and sooner or later you must) you will see that some fields have a property “Picklist” set. To get the picklist values for a particular field you need to use the GetFieldInfo() method of the webservice:

$EntityType = 'Ticket'
$FieldName = 'QueueId'
$TicketInfo = $atws.GetFieldInfo($EntityType)
$QueueIdInfo = $TicketInfo | Where-Object {$_.Name -eq $FieldName}
$QueueIdInfo.PicklistValues | Select value,label

The method is generic and can be used for all entities and fields that have a Picklist of values you need to select from.

This should be enough to get you started, I hope. There are almost no limit to what you can do in Autotask using Powershell. You can create Tickets, TimeEntries, Notes, update prices and much, much more. If you do use any of this I would be happy to hear from you. Good luck!