#!/usr/bin/perl # -- # Copyright (C) 2001-2021 OTRS AG, https://otrs.com/ # -- # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.txt. # -- use strict; use warnings; use utf8; ## nofilter(TidyAll::Plugin::OTRS::Perl::Dumper) # use ../ as lib location use File::Basename; use FindBin qw($RealBin); use lib dirname($RealBin); use JSON; use REST::Client; # This is the HOST for the web service the format is: # <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl my $Host = 'http://localhost/otrs/nph-genericinterface.pl'; my $RestClient = REST::Client->new( { host => $Host, } ); # These are the Controllers and Providers the format is: # /Webservice/<WEB_SERVICE_NAME>/<RESOURCE>/<REQUEST_VALUE> # or # /WebserviceID/<WEB_SERVICE_ID>/<RESOURCE>/<REQUEST_VALUE> # # See the documentation on how to setup Providers. # # This example will retrieve the Ticket with the TicketID = 1 (<REQUEST_VALUE>) my $GetControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket/1'; # This example is the base URL for Ticket Create my $CreateControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket'; # This example will update the Ticket with the TicketID = 1 (<REQUEST_VALUE>) my $UpdateControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket/1'; # This is the base URL for Ticket Search my $SearchControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket'; # This is the base URL for Ticket history with the TicketID = 1 (<REQUEST_VALUE>) my $HistoryControllerAndRequest = '/Webservice/GenericTicketConnectorREST/TicketHistory/1'; # TicketGet Example # See the documentation of OTRSGenericInterfaceREST on how to setup #- webservice #- transport #- operations my $GetParams = { UserLogin => "some agent user login",# to be filled with valid agent login Password=> "some agent user password",# to be filled with valid agent password }; # Build GetParams as part of the URL for REST-GET requests my $QueryParams = $RestClient->buildQuery( %{$GetParams} ); $GetControllerAndRequest .= $QueryParams; $RestClient->GET($GetControllerAndRequest); my $GetResponseCode = $RestClient->responseCode(); if ( $GetResponseCode ne '200' ) { print "Get request failed, response code was: $GetResponseCode\n"; } else { # If the request was answered correctly, we receive a JSON string here. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Just to print out the returned Data structure: use Data::Dumper; print "Get response was:\n"; print Dumper($Data); } # TicketSearch Example # See the documentation of OTRSGenericInterfaceREST on how to setup #- webservice #- transport #- operations my $SearchParams = { UserLogin => "some agent user login",# to be filled with valid agent login Password=> "some agent user password",# to be filled with valid agent password Queues=> ['Raw'], }; # Build SearchParams as part of the URL for REST-GET requests $QueryParams = $RestClient->buildQuery( %{$SearchParams} ); $SearchControllerAndRequest .= $QueryParams; $RestClient->GET($SearchControllerAndRequest); # If the host isn't reachable, wrong configured or couldn't serve the requested page: my $SearchResponseCode = $RestClient->responseCode(); if ( $SearchResponseCode ne '200' ) { print "Search request failed, response code was: $SearchResponseCode\n"; } else { # If the request was answered correctly, we receive a JSON string here. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Just to print out the returned Data structure: use Data::Dumper; print "Search Response was:\n"; print Dumper($Data); } # TicketCreate Example # See the documentation of OTRSGenericInterfaceREST on how to setup # - webservice # - transport # - operations my $CreateOrUpdateParams = { UserLogin => "some agent user login",# to be filled with valid agent login Password=> "some agent user password",# to be filled with valid agent password Ticket=> { Title=> 'some ticket title', Queue=> 'Raw', Lock=> 'unlock', Type=> 'Unclassified', State=> 'new', Priority=> '3 normal', Owner=> 'some agent user login', CustomerUser => 'customer-1', }, Article => { Subject=> 'some subject', Body=> 'some body', ContentType => 'text/plain; charset=utf8', }, }; my $CreateJSONParams = encode_json $CreateOrUpdateParams; my @CreateRequestParam = ( $CreateControllerAndRequest, $CreateJSONParams ); # We have to use REST-POST requests in order to send UserLogin and Password correctly # though other REST methods would fit better. $RestClient->POST(@CreateRequestParam); # If the host isn't reachable, wrong configured or couldn't serve the requested page: my $CreateResponseCode = $RestClient->responseCode(); if ( $CreateResponseCode ne '200' ) { print "Create request failed, response code was: $CreateResponseCode\n"; } else { # If the request was answered correctly, we receive a JSON string here. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Just to print out the returned Data structure: use Data::Dumper; print "Create Response was:\n"; print Dumper($Data); } # TicketUpdate Example # See the documentation of OTRSGenericInterfaceREST on how to setup #- webservice #- transport #- operations my $UpdateJSONParams = encode_json $CreateOrUpdateParams; my @UpdateRequestParam = ( $UpdateControllerAndRequest, $UpdateJSONParams ); # We have to use REST-PATCH requests in order to send UserLogin and Password correctly # though other REST methods would fit better. $RestClient->PATCH(@UpdateRequestParam); # If the host isn't reachable, wrong configured or couldn't serve the requested page: my $UpdateResponseCode = $RestClient->responseCode(); if ( $UpdateResponseCode ne '200' ) { print "Update request failed, response code was: $UpdateResponseCode\n"; } else { # If the request was answered correctly, we receive a JSON string here. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Just to print out the returned Data structure: use Data::Dumper; print "Update response was:\n"; print Dumper($Data); } # TicketHistoryGet Example # See the documentation of OTRSGenericInterfaceREST on how to setup #- webservice #- transport #- operations my $HistoryParams = { UserLogin => "some agent user login",# to be filled with valid agent login Password=> "some agent user password",# to be filled with valid agent password TicketID=> [1], }; # Build SearchParams as part of the URL for REST-GET requests $QueryParams = $RestClient->buildQuery( %{$HistoryParams} ); $HistoryControllerAndRequest .= $QueryParams; $RestClient->GET($HistoryControllerAndRequest); # If the host isn't reachable, wrong configured or couldn't serve the requested page: my $HistoryResponseCode = $RestClient->responseCode(); if ( $HistoryResponseCode ne '200' ) { print "History request failed, response code was: $HistoryResponseCode\n"; } else { # If the request was answered correctly, we receive a JSON string here. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Just to print out the returned Data structure: use Data::Dumper; print "History Response was:\n"; print Dumper($Data); }
#!/usr/bin/perl # -- # Copyright (C) 2001-20201 OTRS AG, https://otrs.com/ # -- # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.txt. # -- use strict; use warnings; use utf8; ## nofilter(TidyAll::Plugin::OTRS::Perl::Dumper) # A ../ használata a lib helyeként use File::Basename; use FindBin qw($RealBin); use lib dirname($RealBin); use JSON; use REST::Client; # Ez a HOST a webszolgáltatásnál. A formátum: # <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl my $Host = 'http://localhost/otrs/nph-genericinterface.pl'; my $RestClient = REST::Client->new( { host => $Host, } ); # Ezek a vezérlők és a szolgáltatók. A formátum: # /Webservice/<WEBSZOLGÁLTATÁS_NEVE/<ERŐFORRÁS>/<KÉRÉS_ÉRTÉK> # vagy # /WebserviceID/<WEBSZOLGÁLTATÁS_AZONOSÍTÓJA>/<ERŐFORRÁS>/<KÉRÉS_ÉRTÉK> # # Nézze meg a dokumentációt a szolgáltatók beállításához. # # Ez a példa le fogja kérni a TicketID = 1 azonosítóval rendelkező jegyet. (<KÉRÉS_ÉRTÉK>) my $GetControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket/1'; # Ez a példa az alap URL a jegylétrehozáshoz my $CreateControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket'; # Ez a példa frissíteni fogja a TicketID = 1 azonosítóval rendelkező jegyet (<KÉRÉS_ÉRTÉK>) my $UpdateControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket/1'; # Ez az alap URL a jegkereséshez my $SearchControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket'; # Ez az alap URL a TicketID = 1 azonosítóval rendelkező jegy előzményéhez (<KÉRÉS_ÉRTÉK>) my $HistoryControllerAndRequest = '/Webservice/GenericTicketConnectorREST/TicketHistory/1'; # Jegylekérés példa # Nézze meg az OTRSGenericInterfaceREST dokumentációját a beállításhoz #- webszolgáltatás #- átvitel #- műveletek my $GetParams = { # érvényes ügyintézői felhasználónévvel kell kitölteni UserLogin => "valamilyen ügyintéző-felhasználó bejelentkezés", # érvényes ügyintézői jelszóval kell kitölteni Password=> "valamilyen ügyintéző-felhasználó jelszó", }; # A GetParams összeállítása az URL részeként a REST-GET kérésekhez my $QueryParams = $RestClient->buildQuery( %{$GetParams} ); $GetControllerAndRequest .= $QueryParams; $RestClient->GET($GetControllerAndRequest); my $GetResponseCode = $RestClient->responseCode(); if ( $GetResponseCode ne '200' ) { print "Get request failed, response code was: $GetResponseCode\n"; } else { # Ha a kérést helyesen válaszolták meg, itt egy JSON szöveget kapunk. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Egyszerűen kiírjuk a kapott adatszerkezetet: use Data::Dumper; print "Get response was:\n"; print Dumper($Data); } # Jegykeresés példa # Nézze meg az OTRSGenericInterfaceREST dokumentációját a beállításhoz #- webszolgáltatás #- átvitel #- műveletek my $SearchParams = { # érvényes ügyintézői felhasználónévvel kell kitölteni UserLogin => "valamilyen ügyintéző-felhasználó bejelentkezés", # érvényes ügyintézői jelszóval kell kitölteni Password=> "valamilyen ügyintéző-felhasználó jelszó", Queues=> ['Raw'], }; # A SearchParams összeállítása az URL részeként a REST-GET kérésekhez $QueryParams = $RestClient->buildQuery( %{$SearchParams} ); $SearchControllerAndRequest .= $QueryParams; $RestClient->GET($SearchControllerAndRequest); # Ha a gép nem érhető el, rosszul van beállítva vagy nem tudta kiszolgálni a kért oldalt: my $SearchResponseCode = $RestClient->responseCode(); if ( $SearchResponseCode ne '200' ) { print "Search request failed, response code was: $SearchResponseCode\n"; } else { # Ha a kérést helyesen válaszolták meg, itt egy JSON szöveget kapunk. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Egyszerűen kiírjuk a kapott adatszerkezetet: use Data::Dumper; print "Search Response was:\n"; print Dumper($Data); } # Jegylétrehozás példa # Nézze meg az OTRSGenericInterfaceREST dokumentációját a beállításhoz #- webszolgáltatás #- átvitel #- műveletek my $CreateOrUpdateParams = { # érvényes ügyintézői felhasználónévvel kell kitölteni UserLogin => "valamilyen ügyintéző-felhasználó bejelentkezés", # érvényes ügyintézői jelszóval kell kitölteni Password=> "valamilyen ügyintéző-felhasználó jelszó", Ticket=> { Title=> 'valamilyen jegycím', Queue=> 'Raw', Lock=> 'unlock', Type=> 'Unclassified', State=> 'new', Priority=> '3 normal', Owner=> 'valamilyen ügyintéző-felhasználó bejelentkezés', CustomerUser => 'felhasználó-1', }, Article => { Subject=> 'valamilyen tárgy', Body=> 'valamilyen törzs', ContentType => 'text/plain; charset=utf8', }, }; my $CreateJSONParams = encode_json $CreateOrUpdateParams; my @CreateRequestParam = ( $CreateControllerAndRequest, $CreateJSONParams ); # REST-POST kéréseket kell használnunk annak érdekében, hogy a UserLogin # és a Password értékét helyesen át tudjuk küldeni, bár a másik REST # metódusnak jobban kellene illeszkednie. $RestClient->POST(@CreateRequestParam); # Ha a gép nem érhető el, rosszul van beállítva vagy nem tudta kiszolgálni a kért oldalt: my $CreateResponseCode = $RestClient->responseCode(); if ( $CreateResponseCode ne '200' ) { print "Create request failed, response code was: $CreateResponseCode\n"; } else { # Ha a kérést helyesen válaszolták meg, itt egy JSON szöveget kapunk. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Egyszerűen kiírjuk a kapott adatszerkezetet: use Data::Dumper; print "Create Response was:\n"; print Dumper($Data); } # Jegyfrissítés példa # Nézze meg az OTRSGenericInterfaceREST dokumentációját a beállításhoz #- webszolgáltatás #- átvitel #- műveletek my $UpdateJSONParams = encode_json $CreateOrUpdateParams; my @UpdateRequestParam = ( $UpdateControllerAndRequest, $UpdateJSONParams ); # REST-PATCH kéréseket kell használnunk annak érdekében, hogy a UserLogin # és a Password értékét helyesen át tudjuk küldeni, bár a másik REST # metódusnak jobban kellene illeszkednie. $RestClient->PATCH(@UpdateRequestParam); # Ha a gép nem érhető el, rosszul van beállítva vagy nem tudta kiszolgálni a kért oldalt: my $UpdateResponseCode = $RestClient->responseCode(); if ( $UpdateResponseCode ne '200' ) { print "Update request failed, response code was: $UpdateResponseCode\n"; } else { # Ha a kérést helyesen válaszolták meg, itt egy JSON szöveget kapunk. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Egyszerűen kiírjuk a kapott adatszerkezetet: use Data::Dumper; print "Update response was:\n"; print Dumper($Data); } # Jegy előzményeinek lekérése példa # Nézze meg az OTRSGenericInterfaceREST dokumentációját a beállításhoz #- webszolgáltatás #- átvitel #- műveletek my $HistoryParams = { # érvényes ügyintézői felhasználónévvel kell kitölteni UserLogin => "valamilyen ügyintéző-felhasználó bejelentkezés", # érvényes ügyintézői jelszóval kell kitölteni Password=> "valamilyen ügyintéző-felhasználó jelszó", TicketID=> [1], }; # A SearchParams összeállítása az URL részeként a REST-GET kérésekhez $QueryParams = $RestClient->buildQuery( %{$HistoryParams} ); $HistoryControllerAndRequest .= $QueryParams; $RestClient->GET($HistoryControllerAndRequest); # Ha a gép nem érhető el, rosszul van beállítva vagy nem tudta kiszolgálni a kért oldalt: my $HistoryResponseCode = $RestClient->responseCode(); if ( $HistoryResponseCode ne '200' ) { print "History request failed, response code was: $HistoryResponseCode\n"; } else { # Ha a kérést helyesen válaszolták meg, itt egy JSON szöveget kapunk. my $ResponseContent = $RestClient->responseContent(); my $Data = decode_json $ResponseContent; # Egyszerűen kiírjuk a kapott adatszerkezetet: use Data::Dumper; print "History Response was:\n"; print Dumper($Data); }
#!/usr/bin/perl -w # -- # otrs.SOAPRequest.pl - sample to send a SOAP request to OTRS Generic Interface Ticket Connector # Copyright (C) 2001-2021 OTRS AG, https://otrs.com/ # -- # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.txt. # -- use strict; use warnings; # use ../ as lib location use File::Basename; use FindBin qw($RealBin); use lib dirname($RealBin); use SOAP::Lite; use Data::Dumper; # --- # Variables to be defined. # this is the URL for the web service # the format is # <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/Webservice/<WEB_SERVICE_NAME> # or # <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/WebserviceID/<WEB_SERVICE_ID> my $URL = 'http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector'; # this name space should match the specified name space in the SOAP transport for the web service. my $NameSpace = 'http://www.otrs.org/TicketConnector/'; # this is operation to execute, it could be TicketCreate, TicketUpdate, TicketGet, TicketSearch # or SessionCreate. and they must to be defined in the web service. my $Operation = 'TicketCreate'; # this variable is used to store all the parameters to be included on a request in XML format. Each # operation has a determined set of mandatory and non mandatory parameters to work correctly. Please # check the OTRS Admin Manual in order to get a complete list of parameters. my $XMLData = ' <UserLogin>some user login</UserLogin> <Password>some password</Password> <Ticket> <Title>some title</Title> <CustomerUser>some customer user login</CustomerUser> <Queue>some queue</Queue> <State>some state</State> <Priority>some priority</Priority> </Ticket> <Article> <Subject>some subject</Subject> <Body>some body</Body> <ContentType>text/plain; charset=utf8</ContentType> </Article> '; # --- # create a SOAP::Lite data structure from the provided XML data structure. my $SOAPData = SOAP::Data ->type( 'xml' => $XMLData ); my $SOAPObject = SOAP::Lite ->uri($NameSpace) ->proxy($URL) ->$Operation($SOAPData); # check for a fault in the soap code. if ( $SOAPObject->fault ) { print $SOAPObject->faultcode, " ", $SOAPObject->faultstring, "\n"; } # otherwise print the results. else { # get the XML response part from the SOAP message. my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content(); # deserialize response (convert it into a perl structure). my $Deserialized = eval { SOAP::Deserializer->deserialize($XMLResponse); }; # remove all the headers and other not needed parts of the SOAP message. my $Body = $Deserialized->body(); # just output relevant data and no the operation name key (like TicketCreateResponse). for my $ResponseKey ( keys %{$Body} ) { print Dumper( $Body->{$ResponseKey} ); } }
#!/usr/bin/perl -w # -- # otrs.SOAPRequest.pl - minta egy SOAP kérés küldéséhez az OTRS általános #felület jegy csatlakozójának # Copyright (C) 2001-20201 OTRS AG, http://otrs.com/ # -- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU AFFERO General Public License as published by # the Free Software Foundation; either version 3 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the # GNU General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA # or see http://www.gnu.org/licenses/agpl.txt. # -- use strict; use warnings; # A ../ használata a lib helyeként use File::Basename; use FindBin qw($RealBin); use lib dirname($RealBin); use SOAP::Lite; use Data::Dumper; # --- # Meghatározandó változók. # Ez az URL a webszolgáltatáshoz # A formátum: # <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/Webservice/<WEBSZOLGÁLTATÁS_NEVE> # vagy # <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/WebserviceID/<WEBSZOLGÁLTATÁS_AZONOSÍTÓJA> my $URL = 'http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector'; # Ennek a névtérnek egyeznie kell a SOAP-átvitelben megadott névtérrel a webszolgáltatásnál. my $NameSpace = 'http://www.otrs.org/TicketConnector/'; # Ez a végrehajtandó művelet, amely lehet: TicketCreate, TicketUpdate, TicketGet, TicketSearch # vagy SessionCreate. És ezeket meg kell határozni a webszolgáltatásban. my $Operation = 'TicketCreate'; # Ez a változó egy kérésnél felvenni kívánt összes paraméter tárolásához használható # XML-formátumban. Minden egyes műveletnek egy meghatározott kötelező és nem kötelező # paraméterek halmaza van a helyes működéshez. Nézze meg az OTRS adminisztrációs # kézikönyvet azért, hogy beszerezhesse a paraméterek teljes listáját. my $XMLData = ' <UserLogin>valamilyen felhasználói bejelentkezés</UserLogin> <Password>valamilyen jelszó</Password> <Ticket> <Title>valamilyen cím</Title> <CustomerUser>valamilyen ügyfél-felhasználó bejelentkezés</CustomerUser> <Queue>valamilyen várólista</Queue> <State>valamilyen állapot</State> <Priority>valamilyen prioritás</Priority> </Ticket> <Article> <Subject>valamilyen tárgy</Subject> <Body>valamilyen törzs</Body> <ContentType>text/plain; charset=utf8</ContentType> </Article> '; # --- # Egy SOAP::Lite adatszerkezet létrehozása a megadott XML-adatszerkezetből. my $SOAPData = SOAP::Data ->type( 'xml' => $XMLData ); my $SOAPObject = SOAP::Lite ->uri($NameSpace) ->proxy($URL) ->$Operation($SOAPData); # Hiba keresése a SOAP-kódban. if ( $SOAPObject->fault ) { print $SOAPObject->faultcode, " ", $SOAPObject->faultstring, "\n"; } # Egyébként az eredmények kiírása. else { # Az XML-válaszrész lekérése a SOAP-üzenetből. my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content(); # A válasz visszaalakítása (átalakítás egy Perl-szerkezetre). my $Deserialized = eval { SOAP::Deserializer->deserialize($XMLResponse); }; # Az összes fejléc és a SOAP-üzenet egyéb nem szükséges részeinek eltávolítása. my $Body = $Deserialized->body(); # Csak a fontos adatok kiírása, és a műveletnév kulcsot nem (mint például # TicketCreateResponse). for my $ResponseKey ( keys %{$Body} ) { print Dumper( $Body->{$ResponseKey} ); } }