Accessing to the tickets /data via API

English! place to talk about OTRS development, programming and coding
Post Reply
quadrivium
OTRS newbie
Posts: 34
Joined: 23 Mar 2020, 10:36
OTRS Version?: 6.0.10
Real Name: Paolo Ponzano
Company: Quadrivium

Accessing to the tickets /data via API

Post by quadrivium »

Hello,
Please excuse me if I start asking a question but I've been asked to find a way to read daily the tickets then post them back to a system that my colleagues wrote. I have to tell that I'm not familiar with Perl (I came from 15+ years on .NET), but if it's the case I can studying it for the needs that I've.

My first question is (but as I've read from docs, not) it's possible to access OTRS via Web API?
The second one is (if the first is not possible), it's best to access directly to the database or via Perl API?

PS. I'm using OTRS 6.0.10 Community Edition

RStraub
OTRS guru
Posts: 2196
Joined: 13 Mar 2014, 09:16
OTRS Version?: 6.0.14
Real Name: Rolf Straub

Re: Accessing to the tickets /data via API

Post by RStraub »

Hello and welcome to the forum!

You can make OTRS accessible via WebAPI, but for internal processes I find it easier to do it with the Perl-API.

Good readup for the API is here:
https://doc.otrs.com/doc/api/otrs/6.0/Perl/index.html

And here is a standalone Perl Script that searches Tickets based on a Queue, State and DF-Date-Field:

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use lib '/opt/otrs/';
use lib '/opt/otrs/Kernel/cpan-lib';
use lib '/opt/otrs/Custom';

use Kernel::System::ObjectManager;
use Data::Dumper;

local $Kernel::OM = Kernel::System::ObjectManager->new(
    'Kernel::System::Log' => {
        LogPrefix => "$0",
    },
);

my $TicketObject    = $Kernel::OM->Get('Kernel::System::Ticket');

my %SearchParam = (
    Result => 'ARRAY',
    Queues => ['MyQueueName'],
    StateType => ['open', 'new', 'pending reminder', 'pending auto'],
    DynamicField_MyDynamicDateField => {
        SmallerThan => "2019-06-30 12:00:00",
    },
    DynamicField_MyDynamicDateField => {
        GreaterThan => "2019-06-01 12:00:00",
    },
    UserID => 1,
);
my @TicketIDs = $TicketObject->TicketSearch(
    %SearchParam,
);

# Do something with the TicketIDs, or dump them:
printf Dumper(\@TicketIDs);
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS

quadrivium
OTRS newbie
Posts: 34
Joined: 23 Mar 2020, 10:36
OTRS Version?: 6.0.10
Real Name: Paolo Ponzano
Company: Quadrivium

Re: Accessing to the tickets /data via API

Post by quadrivium »

Thanks RStraub for the information... but a thing it's not clear to me, how do I connect your script with OTRS?
Shall this be placed inside the folder where OTRS is contained?

Thanks in advance
Paolo

RStraub
OTRS guru
Posts: 2196
Joined: 13 Mar 2014, 09:16
OTRS Version?: 6.0.14
Real Name: Rolf Straub

Re: Accessing to the tickets /data via API

Post by RStraub »

Hey,

this would be done on the console.

For example, make a new folder in ~otrs called "scripts" and write the code to a file , e.g. "searchTickets.pl". Then make it executable "chmod +x searchTickets.pl" and run it "./searchTickets.pl".

From what I understood, you don't need to connect it to OTRS, but run it on a daily basis ? So maybe via CronJob ?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS

quadrivium
OTRS newbie
Posts: 34
Joined: 23 Mar 2020, 10:36
OTRS Version?: 6.0.10
Real Name: Paolo Ponzano
Company: Quadrivium

Re: Accessing to the tickets /data via API

Post by quadrivium »

My idea was to have a windows service that reads those data, then it posts on 2 different systems, one is Zoho projects and the other is a custom tool we work on.

So currently I've got 2 solutions, one is to work via Web API, so if I have to query I get the data, or to access via script as you told me but in this case, I need to install my windows service on the hosting machine, then execute the script from my application

zzz
OTRS ninja
Posts: 458
Joined: 15 Dec 2016, 15:13
OTRS Version?: 3.x - 6.0.x
Real Name: Emin Yazi
Company: Efflux GmbH
Contact:

Re: Accessing to the tickets /data via API

Post by zzz »

Hey,

For your windows program, it's fine to access the database directly as long as you're only reading out of it.
Web services can be created via the Generic Interface.

Best regards
Emin
Professional OTRS services for development, consulting, hosting and support:
efflux.de – German | efflux.de/en/ – English

Free and premium OTRS add-ons (TextModule, AdBlocker, ModernSkin ... growing): portal.efflux.de

RStraub
OTRS guru
Posts: 2196
Joined: 13 Mar 2014, 09:16
OTRS Version?: 6.0.14
Real Name: Rolf Straub

Re: Accessing to the tickets /data via API

Post by RStraub »

Indeed, if you want to access it from a different machine, probably go WebServices.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS

quadrivium
OTRS newbie
Posts: 34
Joined: 23 Mar 2020, 10:36
OTRS Version?: 6.0.10
Real Name: Paolo Ponzano
Company: Quadrivium

Re: Accessing to the tickets /data via API

Post by quadrivium »

Excuse me , is there a sample that explains how to call a webservice just created? I usually use PostMan, but in this case, I don't know which endpoint to call.
Here's the endpoint I've created
otrs_1.PNG
and the inner page
otrs_2.PNG
Thanks in advance
You do not have the required permissions to view the files attached to this post.

root
Moderator
Posts: 2084
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6
Real Name: Roy Kaldung
Company: Znuny Inc.
Contact:

Re: Accessing to the tickets /data via API

Post by root »

Hi,

Why don't you import the existing web service configuration from https://github.com/OTRS/otrs/tree/rel-6 ... ebservices ?

There are enough examples out there for this configuration.

- Roy
OTRS 5/6 CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Do you need professional services for the ((OTRS)) Community Edition? Check out https://www.znuny.com/

quadrivium
OTRS newbie
Posts: 34
Joined: 23 Mar 2020, 10:36
OTRS Version?: 6.0.10
Real Name: Paolo Ponzano
Company: Quadrivium

Re: Accessing to the tickets /data via API

Post by quadrivium »

I've managed to create a session doing

http://172.31.254.7/otrs/nph-genericint ... rLogin=xxx

I don't understand why it doesn't accept SessionCreate... now that I've got the SessionId, where should I pass it at?

Thanks
Paolo

root
Moderator
Posts: 2084
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6
Real Name: Roy Kaldung
Company: Znuny Inc.
Contact:

Re: Accessing to the tickets /data via API

Post by root »

Hi,

Check this folder https://github.com/OTRS/otrs/tree/rel-6 ... ion/Ticket
The payload is described inside each operation, see as an example https://github.com/OTRS/otrs/blob/rel-6 ... Get.pm#L64

- Roy
OTRS 5/6 CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Do you need professional services for the ((OTRS)) Community Edition? Check out https://www.znuny.com/

Post Reply