Skip to content

yothinix/autotask-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autotask API Client

This is a proof of concept of using Autotask SOAP API in Python

Requirement

  • In order to use Pipfile, you need to install pipenv on your system
  • You need to add .env file in the project directory in order to make it work. The example of env are shown below
[email protected]
AUTOTASK_PASSWORD=password

Making Request

Making Query

To query you need to specify Entity you want to query, A field for filter and it's value. You also need to specify a list of return field otherwise it will return None

from autotask import Autotask


client = Autotask()
client.username = '<username>'
client.password = '<password>'

ticket, status_code = client.query(
    entity='Ticket',
    filter_field='ticketnumber',
    filter_value='T20180220.0001',
    select_fields=(
        'id', 'AccountID', 'CreateDate', 'DueDateTime',
        'TicketNumber', 'Title', 'Description', 'AssignedResourceID'
    )
)

The wrapper is equivalent to this XML body

<env:Envelope
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tns="http://autotask.net/ATWS/v1_5/"
	xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
	<env:Body>
		<tns:query
			xmlns="http://autotask.net/ATWS/v1_5/">
			<sXML>
				<![CDATA[
          <queryxml>
            <entity>Ticket</entity>
            <query>
              <field>ticketnumber
                <expression op="equals">T20180220.0001</expression>
              </field>
            </query>
          </queryxml>]]>
			</sXML>
		</tns:query>
	</env:Body>
</env:Envelope>

Create Ticket Note

To create entity you need to specify Entity you want to create, A dictionary of update object. You also need to specify a list of return field otherwise it will return None

from autotask import Autotask


client = Autotask()
client.username = '<username>'
client.password = '<password>'

ticket_note, status_code = client.create(
    entity='TicketNote',
    update_object={
        'Description': 'Comment: "Great service as always!"'
        'NoteType': '1',
        'Publish': '1',
        'TicketID': '7872',
        'Title': 'Good rating from Cory Black'
    },
    select_fields=(
        'id', 'CreatorResourceID', 'Description', 'LastActivityDate',
        'NoteType', 'Publish', 'TicketID', 'Title'
    )
)

The wrapper is equivalent to this XML body

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<create
			xmlns="http://autotask.net/ATWS/v1_5/">
			<Entities>
				<Entity xsi:type="TicketNote">
					<Description>Comment: "Great service as always! !!!"</Description>
					<NoteType>1</NoteType>
					<Publish>1</Publish>
					<TicketID>7872</TicketID>
					<Title>Good rating from Cory Black</Title>
				</Entity>
			</Entities>
		</create>
	</soap:Body>
</soap:Envelope>

Update User-Defined Fields on Ticket Entity

To update User-Defined Fields, You need to specify target Entity and lookup_keys in dictionary format. Then, you need to specified User-Defined Fields Name and value. Lastly, You also need to specify a list of return field otherwise it will return None

from autotask import Autotask


client = Autotask()
client.username = '<username>'
client.password = '<password>'

update_ticket_satisfaction, status_code = client.update_udf(
    entity='Ticket',
    lookup_keys={
        'id': '7872',
        'Title': 'This is Man test ticket',
        'Status': '1',
        'Priority': '1',
        'DueDateTime': '2018-02-21T01:38:00',
        'AccountID': '0',
        'AssignedResourceID': '29682885',
        'AssignedResourceRoleID': '29683436'
    },
    field='Satisfaction',
    value='1',
    select_fields=(
        'id', 'AccountID', 'CreateDate', 'DueDateTime',
        'TicketNumber', 'Title', 'Description', 'AssignedResourceID'
    )
)

The wrapper is equivalent to this XML body

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <update xmlns="http://autotask.net/ATWS/v1_5/">
      <Entities>
        <Entity xsi:type="Ticket">
          <id>7872</id>
          <Title>This is Man test ticket</Title>
          <Status>1</Status>
          <Priority>1</Priority>
          <DueDateTime>2018-02-21T01:38:00</DueDateTime>
          <AccountID>0</AccountID>
          <AssignedResourceID xsi:type="xsd:int">29682885</AssignedResourceID>
          <AssignedResourceRoleID xsi:type="xsd:int">29683436</AssignedResourceRoleID>

					<UserDefinedFields>
					  <UserDefinedField>
					    <Name>Satisfaction</Name>
					    <Value>3</Value>
					  </UserDefinedField>
					</UserDefinedFields>

        </Entity>
      </Entities>
    </update>
  </soap:Body>
</soap:Envelope>

Get Zone Info

from autotask import Autotask


client = Autotask()
client.username = '<username>'
client.password = '<password>'


get_zone_info = client.get_zone_info()

The wrapper is equivalent to this XML body

<env:Envelope
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:tns="http://autotask.net/ATWS/v1_5/"
	xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
	<env:Body>
    <getZoneInfo xmlns="http://autotask.net/ATWS/v1_5/">
      <UserName>Username</UserName>
    </getZoneInfo>
	</env:Body>
</env:Envelope>

Development

  • To execute the test, running
pipenv run test

About

A proof of concept of using autotask API in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages