Skip to content
Snippets Groups Projects
user avatar
Robert Habermann authored
7eafe703
History

Overview

Build Status Docs Build Status

PyOTRS is a Python wrapper for accessing OTRS (Version 5) using the REST API.

Features

Access an OTRS instance to:

* create a new Ticket
* get the data of a specific Ticket
* search for Tickets
* update existing Tickets

Some of the most notable methods provided are:

* Client.session_create ("login")
* Client.ticket_create
* Client.ticket_get_by_list  (takes a list)
* Client.ticket_get_by_number  (takes a string)
* Client.ticket_search
* Client.ticket_update

More details can be found here

Installation

Dependencies

Dependencies are installed automatically

pip:

- python-requests
- click (for PyOTRS Shell CLI)
- colorama (for colors in PyOTRS Shell CLI)

Install

install:

pip install PyOTRS

or consider using a virtual environment:

virtualenv venv
source venv/bin/activate
pip install PyOTRS

Python Usage

Quickstart

Get Ticket with TicketID 1 from OTRS over the REST API:

from pyotrs import Client
client = Client("https://otrs.example.com", "GenericTicketConnectorREST", "root@localhost", "x")
client.session_create()
client.ticket_get_by_id(1)

More Examples

  • instantiate a Client object called client
  • create a session ("login") on client
  • get the Ticket with ID 1
>>> from pyotrs import Article, Client, Ticket
>>> client = Client("http://otrs.example.com", "GenericTicketConnectorREST", "root@localhost", "password")
>>> client.session_create()
True
>>> client.ticket_get_by_id(1)
True
>>> client.result_list_ticket_get
[<Ticket: 1>]
>>> my_ticket = client.result_list_ticket_get[0]
>>> my_ticket.TicketNumber
u'2010080210123456'
>>> my_ticket.Title
u'Welcome to OTRS!'
>>> my_ticket.to_dct()  # Show complete ticket
  • add an Article to Ticket with ID 1
>>> my_article = Article({"Subject": "Subj", "Body": "New Body"})
>>> client.ticket_update(1, article=my_article)
True
  • get Articles and Attachments
>>> client.ticket_get_by_id(1, articles=1, attachments=1)
>>> my_ticket = client.result_list_ticket_get[0]
>>> my_ticket.list_articles
[<ArticleID: 3>, <ArticleID: 4>
>>> my_ticket.list_dynamic_field
[<DynamicField: ProcessManagementActivityID: None>, <DynamicField: ProcessManagementProcessID: None>]

Tips

When using ipython you could run into UTF8 encoding issues on Python2. This is a workaround that can help:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

PyOTRS Shell CLI

The PyOTRS Shell CLI is a kind of "proof-of-concept" for the PyOTRS wrapper library.

Attention: PyOTRS can only retrieve Ticket data at the moment!

Usage

Get a Ticket:

PyOTRS get -b https://otrs.example.com/ -w GenericTicketConnectorREST -u root@localhost -p password -t 1
Starting PyOTRS CLI
No config file found at: /home/user/.pyotrs
Connecting to https://otrs.example.com/ as user..
Ticket:         Welcome to OTRS!
Queue:          Raw
State:          closed successful
Priority:       3 normal

Full Ticket:
{u'Ticket': {u'TypeID': 1, [...]

Get usage information:

$: PyOTRS -h
Usage: PyOTRS [OPTIONS] COMMAND [ARGS]...

Options:
  --version      Show the version and exit.
  --config PATH  Config File
  -h, --help     Show this message and exit.

Commands:
  get  PyOTRS get command

$: PyOTRS get -h
Starting PyOTRS CLI
No config file found at: /home/user/.pyotrs
Usage: PyOTRS get [OPTIONS]

  PyOTRS get command

Options:
  -b, --baseurl TEXT         Base URL
  -w, --webservicename TEXT  Webservice Name
  -u, --username TEXT        Username
  -p, --password TEXT        Password
  -t, --ticket-id INTEGER    Ticket ID
  -h, --help                 Show this message and exit.

Get a Ticket "interactively":

$: PyOTRS get
Starting PyOTRS CLI
No config file found at: /home/user/.pyotrs
Baseurl: http://otrs.example.com
Webservicename: GenericTicketConnectorREST
Username: user
Password:
Ticket id: 1

Connecting to https://otrs.example.com as user..

Ticket:         Welcome to OTRS!
Queue:          Raw
State:          closed successful
Priority:       3 normal

Full Ticket:
{u'Ticket': {u'TypeID': 1  [...]

Provide Config

There are four ways to provide config values:

1. interactively when prompted
2. as commandline arguments when calling (checkout -h/--help)
3. as settings in the environment
4. in a config file (default location: ~/.pyotrs)

Both the config file and the environment use the same variable names:

PYOTRS_BASEURL=http://otrs.example.com
PYOTRS_WEBSERVICENAME=GenericTicketConnectorREST
PYOTRS_USERNAME=root@localhost
PYOTRS_PASSWORD=otrs_password

License

MIT License