[SOLVED] Ticket::TicketGet route in my web service not working

Moderator: crythias

Locked
ATD39401
Znuny newbie
Posts: 21
Joined: 28 Jun 2024, 14:38
Znuny Version: 6.0.44
Real Name: Amber Denton
Company: UTK College of Veterinary Medicine

[SOLVED] Ticket::TicketGet route in my web service not working

Post by ATD39401 »

Hello everyone! I am developing an automation tool that collects ticket IDs from the Kernel::GenericInterface::Operation::Ticket::TicketSearch interface and performs operations on each ticket. I'm trying to access ticket information by looping through each ID and calling the Kernel::GenericInterface::Operation::Ticket::TicketGet interface, but the API call seemingly doesn't work like Ticket::TicketSearch's call.

Python script for grabbing relevant ticket IDs

Code: Select all

# OTRSLogin and OTRSPassword defined elsewhere
reqHeaders = {'Accept': 'application/json'}
webservice = 'https://[HOST]/otrs/nph-genericinterface.pl/Webservice/ConvCopierReports'

urlForAPI = webservice + '/TicketSearch?'
params = dict(
    QueueID=25,
    TicketCreateTimeNewerMinutes=42300,
    StateType='Open',
    UserLogin=OTRSLogin,
    Password=OTRSPassword
)
print(urlForAPI)		# https://[HOST]/otrs/nph-genericinterface.pl/Webservice/ConvCopierReports/TicketSearch?
response = requests.get(url=urlForAPI, params=params, headers=reqHeaders)
printerTicketIDs = response.json()['TicketID']
The documentation suggests that the query should start in a similar format, i.e., [web_service_path]/TicketSearch?[params] and [web_service_path]/TicketGet?[params] respectively. However the following code doesn't respond with JSON-formatted ticket data, instead giving an error in the debugger that reads HTTP::REST Error while determine Operation for request URI '/TicketGet'. Should I not use TicketID as a parameter here? If so, how should I get ticket data like the Article, Subject, customer email, etc.?

Code: Select all

for ticketID in printerTicketIDs:
    # pull the Article data for every ticket ID we returned from the "Printers" queue
    urlForAPI = webservice + '/TicketGet?'
    params = dict(
        TicketID=ticketID,
    	UserLogin=OTRSLogin,
	Password=OTRSPassword
    )
    response = requests.get(url=urlForAPI, params=params, headers=reqHeaders)
    print(response)	# 500 response each time
Attached is my web service YAML file. Thank you in advance for any assistance that can be provided!
EDIT: changed urlForAPI in the second code snipped because I erroneously typed the entry point
You do not have the required permissions to view the files attached to this post.
Last edited by ATD39401 on 02 Aug 2024, 17:27, edited 1 time in total.
zzz
Znuny superhero
Posts: 914
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Ticket::TicketGet route in my web service not working

Post by zzz »

Hey,

The routing for TicketGet in line 57 of your YAML doesn't match.

Try to change your configuration from:

Code: Select all

Route: /TicketGet/:TicketId
to

Code: Select all

Route: /TicketGet
— Emin
Professional Znuny and OTRS services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
ATD39401
Znuny newbie
Posts: 21
Joined: 28 Jun 2024, 14:38
Znuny Version: 6.0.44
Real Name: Amber Denton
Company: UTK College of Veterinary Medicine

Re: Ticket::TicketGet route in my web service not working

Post by ATD39401 »

Thank you for pointing that out! I was staring at that route for awhile and hadn't noticed.

How would one return the Article data (body text, to email, etc.) from the ticket data? I don't see the Article nested in the JSON when I return tickets, as shown in the documentation here. https://otrscommunityedition.com/doc/ap ... et.pm.html

example output I get from OTRS web service debugger

Code: Select all

$VAR1 = {
  'Ticket' => [
    {
      'Age' => 15483,
      'ArchiveFlag' => 'n',
      'ChangeBy' => 3,
      'Changed' => [DATETIME],
      'CreateBy' => 3,
      'Created' => [DATETIME],
      'CustomerID' => [CUSTOMER],
      'CustomerUserID' => [ID],
      'EscalationResponseTime' => 0,
      'EscalationSolutionTime' => 0,
      'EscalationTime' => 0,
      'EscalationUpdateTime' => 0,
      'GroupID' => 5,
      'Lock' => 'lock',
      'LockID' => 2,
      'Owner' => [OWNER],
      'OwnerID' => 3,
      'Priority' => '3 normal',
      'PriorityID' => 3,
      'Queue' => [QUEUE],
      'QueueID' => 5,
      'RealTillTimeNotUsed' => 0,
      'Responsible' => 'root@localhost',
      'ResponsibleID' => 1,
      'SLAID' => '',
      'ServiceID' => '',
      'State' => 'open',
      'StateID' => 4,
      'StateType' => 'open',
      'TicketID' => 1644553,
      'TicketNumber' => [TICKETNO],
      'TimeUnit' => '0.25',
      'Title' => [TITLE],
      'Type' => 'default',
      'TypeID' => 1,
      'UnlockTimeout' => 1722006486,
      'UntilTime' => 0
    }
  ]
};
zzz
Znuny superhero
Posts: 914
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Ticket::TicketGet route in my web service not working

Post by zzz »

At the top, you can see the available parameters:

Code: Select all

    
    my $Result = $OperationObject->Run(
        Data => {
            UserLogin            => 'some agent login',                            # UserLogin or CustomerUserLogin or SessionID is
                                                                                   #   required
            CustomerUserLogin    => 'some customer login',
            SessionID            => 123,

            Password             => 'some password',                               # if UserLogin or customerUserLogin is sent then
                                                                                   #   Password is required
            TicketID             => '32,33',                                       # required, could be coma separated IDs or an Array
            DynamicFields        => 0,                                             # Optional, 0 as default. Indicate if Dynamic Fields
                                                                                   #     should be included or not on the ticket content.
            Extended             => 1,                                             # Optional, 0 as default
            AllArticles          => 1,                                             # Optional, 0 as default. Set as 1 will include articles
                                                                                   #     for tickets.
            ArticleSenderType    => [ $ArticleSenderType1, $ArticleSenderType2 ],  # Optional, only requested article sender types
            ArticleOrder         => 'DESC',                                        # Optional, DESC,ASC - default is ASC
            ArticleLimit         => 5,                                             # Optional
            Attachments          => 1,                                             # Optional, 0 as default. If it's set with the value 1,
                                                                                   # attachments for articles will be included on ticket data
            GetAttachmentContents = 1                                              # Optional, 1 as default. 0|1,
            HTMLBodyAsAttachment => 1                                              # Optional, If enabled the HTML body version of each article
                                                                                   #    is added to the attachments list
        },
    );
Professional Znuny and OTRS services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
Locked