Ticket

Added in version 2.4.0.

Requires Pro Edition and Helpdesk plugin >= 4.1.12.

Manager

All operations on the Ticket resource are provided by its manager. To get access to it you have to call redmine.ticket where redmine is a configured redmine object. See the Configuration about how to configure redmine object.

Create methods

create

redminelib.managers.ResourceManager.create(**fields)

Creates new Ticket resource with given fields and saves it to the Helpdesk plugin.

Parameters:
  • contact (dict) – (required). Can be either existing (the only required field is email then) contact or a new one, check Contact docs for a list of fields.

  • issue (dict) – (required). New Issue will be created for this ticket, check Issue docs for a list of fields, required fields are:

    • project_id - ticket issue’s project id

    • tracker_id - be sure to set the correct tracker from Helpdesk plugin settings

    • subject - ticket issue’s subject

    • description - ticket issue’s content

  • ticket_date (string or date object) – (required). Ticket date.

  • ticket_time (string) – (required). Ticket time.

  • source (string) – (optional). Ticket source:

    • 0 - email

    • 1 - web

    • 2 - phone

    • 4 - conversation

  • helpdesk_send_as (string) – (optional). Send as:

    • 1 - notification

    • 2 - initial message

  • to_address (string) – (optional). To addresses (, separated).

  • cc_address (string) – (optional). Cc addresses (, separated).

  • is_incoming (bool) – (optional). Whether ticket is incoming.

Returns:

Resource object

>>> ticket = redmine.ticket.create(
...     source='2',
...     helpdesk_send_as='2',
...     ticket_date='2023-01-10',
...     ticket_time='10:01',
...     to_address='support@product.com',
...     cc_address='managers@product.com,jsmith@product.com',
...     is_incoming=True,
...     issue={
...         'project_id': 'helpdesk',
...         'subject': 'ticket subject',
...         'tracker_id': 6,
...         'description': 'ticket content',
...     },
...     contact={
...         'email': 'existing_client@mail.com',
...     }
... )
>>> ticket
<redminelib.resources.Ticket #123>

new

redminelib.managers.ResourceManager.new()

Creates new empty Ticket resource, but saves it to the Helpdesk plugin only when save() is called, also calls pre_create() and post_create() methods of the Resource object. Valid attributes are the same as for create() method above.

Returns:

Resource object

>>> ticket = redmine.ticket.new()
>>> ticket.source = '2'
>>> ticket.helpdesk_send_as = '2'
>>> ticket.ticket_date = '2023-01-10'
>>> ticket.ticket_time = '10:01'
>>> ticket.to_address = 'support@product.com'
>>> ticket.cc_address = 'managers@product.com,jsmith@product.com'
>>> ticket.is_incoming = True
>>> ticket.issue = {
...     'project_id': 'helpdesk',
...     'subject': 'ticket subject',
...     'tracker_id': 6,
...     'description': 'ticket content',
... }
>>> ticket.contact = {
...     'email': 'existing_client@mail.com',
... }
>>> ticket.save()
<redminelib.resources.Ticket #123>

Read methods

get

redminelib.managers.ResourceManager.get(resource_id, **params)

Returns single Ticket resource from the Helpdesk plugin by its id.

Parameters:
  • resource_id (int) – (required). Id of the ticket.

  • include (list) – (optional). Fetches associated data in one call. Accepted values:

    • journals

Returns:

Resource object

>>> ticket = redmine.ticket.get(123, include=['journals'])
>>> ticket
<redminelib.resources.Ticket #123>

Hint

Ticket resource object provides you with on demand includes. On demand includes are the other resource objects wrapped in a ResourceSet which are associated with a Ticket resource object. Keep in mind that on demand includes are retrieved in a separate request, that means that if the speed is important it is recommended to use get() method with include keyword argument. On demand includes provided by the Ticket resource object are the same as in the get() method above:

>>> ticket = redmine.ticket.get(123)
>>> ticket.journals
<redminelib.resultsets.ResourceSet object with TicketJournal resources>

all

redminelib.managers.ResourceManager.all(**params)

Returns all Ticket resources from the Helpdesk plugin.

Parameters:
  • limit (int) – (optional). How much resources to return.

  • offset (int) – (optional). Starting from what resource to return the other resources.

Returns:

ResourceSet object

>>> tickets = redmine.ticket.all(limit=50)
>>> tickets
<redminelib.resultsets.ResourceSet object with Ticket resources>

filter

redminelib.managers.ResourceManager.filter(**filters)

Returns Ticket resources that match the given lookup parameters.

Parameters:
  • source (string) – (optional). Get tickets for the given source.

  • from_address (string) – (optional). Get tickets that were sent from this address.

  • limit (int) – (optional). How much resources to return.

  • offset (int) – (optional). Starting from what resource to return the other resources.

Returns:

ResourceSet object

>>> tickets = redmine.ticket.filter(source='2', from_address='client@mail.com')
>>> tickets
<redminelib.resultsets.ResourceSet object with Ticket resources>

Hint

You can also get tickets from a Contact resource object directly using tickets on demand includes:

>>> contact = redmine.contact.get(123)
>>> contact.tickets
<redminelib.resultsets.ResourceSet object with Ticket resources>

Update methods

update

redminelib.managers.ResourceManager.update(resource_id, **fields)

Updates values of given fields of a Ticket resource and saves them to the Helpdesk plugin.

Parameters:
  • resource_id (int) – (required). Ticket id.

  • ticket_date (string or date object) – (optional). Ticket date.

  • ticket_time (string) – (optional). Ticket time.

  • source (string) – (optional). Ticket source:

    • 0 - email

    • 1 - web

    • 2 - phone

    • 4 - conversation

  • from_address (string) – (optional). Updates contact of the ticket.

  • to_address (string) – (optional). To addresses (, separated).

  • cc_address (string) – (optional). Cc addresses (, separated).

  • is_incoming (bool) – (optional). Whether ticket is incoming.

Returns:

True

>>> redmine.ticket.update(
...     123,
...     source='2',
...     ticket_date='2023-01-10',
...     ticket_time='10:01',
...     from_address='client@mail.com',
...     to_address='support@product.com',
...     cc_address='managers@product.com,jsmith@product.com',
...     is_incoming=True
... )
True

save

redminelib.resources.Expense.save(**attrs)

Saves the current state of a Ticket resource to the Helpdesk plugin. Attrs that can be changed are the same as for update() method above.

Returns:

Resource object

>>> ticket = redmine.ticket.get(123)
>>> ticket.source = '2'
>>> ticket.ticket_date = '2023-01-10'
>>> ticket.ticket_time = '10:01'
>>> ticket.to_address = 'support@product.com'
>>> ticket.cc_address = 'managers@product.com,jsmith@product.com'
>>> ticket.is_incoming = True
>>> ticket.save()
<redminelib.resources.Ticket #123>

Added in version 2.1.0: Alternative syntax was introduced.

>>> ticket = redmine.ticket.get(123).save(
...     source='2',
...     ticket_date='2023-01-10',
...     ticket_time='10:01',
...     to_address='support@product.com',
...     cc_address='managers@product.com,jsmith@product.com',
...     is_incoming=True
... )
>>> ticket
<redminelib.resources.Ticket #123>

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single Ticket resource from the Helpdesk plugin by its id.

Parameters:

resource_id (int) – (required). Ticket id.

Returns:

True

>>> redmine.ticket.delete(123)
True
redminelib.resources.Ticket.delete()

Deletes current Ticket resource object from the Helpdesk plugin.

Returns:

True

>>> ticket = redmine.ticket.get(1)
>>> ticket.delete()
True

Export

Not supported by Helpdesk plugin, but as tickets are basically issues and share the same ID, one can export Issue resources and get most of the ticket information from them.

Journals

The history of a ticket is represented as a ResourceSet of TicketJournal resources. Currently the following operations are possible:

create

To reply to a ticket, i.e. create a new record in ticket history, i.e. new journal:

>>> ticket = redmine.ticket.get(1)
>>> journal = ticket.reply(
...     status_id=2,
...     content='we are working on your issue',
...     uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
>>> journal
<redminelib.resources.TicketJournal #321>

Or if you know the issue_id beforehand:

>>> journal = redmine.ticket_journal.create(
...     issue_id=123,
...     status_id=2,
...     content='we are working on your issue',
...     uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
>>> journal
<redminelib.resources.TicketJournal #321>

read

Recommended way to access ticket journals is through associated data includes:

>>> ticket = redmine.ticket.get(1, include=['journals'])
>>> ticket.journals
<redminelib.resultsets.ResourceSet object with TicketJournal resources>

But they can also be accessed through on demand includes:

>>> ticket = redmine.ticket.get(1)
>>> ticket.journals
<redminelib.resultsets.ResourceSet object with TicketJournal resources>

After that they can be used as usual:

>>> for journal in ticket.journals:
...     print(journal.id, journal.notes)
...
1 foobar
2 lalala
3 hohoho

update

To update notes attribute (the only attribute that can be updated) of a journal:

>>> ticket = redmine.ticket.get(1, include=['journals'])
>>> for journal in ticket.journals:
...     journal.save(notes='setting notes to a new value')
...

Or if you know the id beforehand:

>>> redmine.ticket_journal.update(1, notes='setting notes to a new value')
True

delete

To delete a journal, set its notes attribute to an empty string:

>>> ticket = redmine.ticket.get(1, include=['journals'])
>>> for journal in ticket.journals:
...     journal.save(notes='')
...

Or if you know the id beforehand:

>>> redmine.ticket_journal.update(1, notes='')
True

Note

You can only delete a journal that doesn’t have the associated details attribute.