我已在管理控制台中导入此 Restfull Web service并使用此URL成功创建并获取票证信息
http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/1.
但问题是当我获得票证信息时链接的配置项信息不会出现.
我在google上做了很多搜索,发现票证可以通过OTRS GUI链接到Config Item,在AgentTicketzoom页面中会显示,我希望通过Web服务完成.
任何人都可以帮助我解决这个问题,或者建议一些关于如何创建Web服务以从票证中获取链接对象信息的文档.
更新#1
我成功地将web控制器添加到我现有的Ticket连接器.网址是http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject与POST Call.but我收到此错误
{“faultcode”:“Server”,“faultstring”:“没有ConfigObject!”}
我也检查了初始参数
$VAR1 = { 'Password' => '1234567','RequestMethod' => 'POST','SourceKey' => '1','SourceObject' => 'Ticket','State' => 'valid','TargetKey' => '2','Targetobject' => 'ITSMConfigItem','Type' => 'ParentChild','UserID' => '1','UserLogin' => 'XXXXX.XXXX@XXXX.com'};
$VAR1 = { 'ErrorMessage' => 'Got no ConfigObject!','Success' => 0};
解决方法
首先,您应该编写一个新的通用接口连接器操作,该操作将处理来自LinkObject类的方法LinkAdd(APIdoc)
然后通过新的XML文件创建并注册新操作,如下所示:
文件名:GenericInterfaceLinkObjectConnector.xml
<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="1.0" init="Application">
<ConfigItem Name="GenericInterface::Operation::Module###LinkObject::LinkAdd" required="0" Valid="1">
<Description Translatable="1">GenericInterface module registration for the operation layer.</Description>
<Group>GenericInterface</Group>
<SubGroup>GenericInterface::Operation::ModuleRegistration</SubGroup>
<Setting>
<Hash>
<Item Key="Name">LinkAdd</Item>
<Item Key="Controller">LinkObject</Item>
<Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item>
</Hash>
</Setting>
</ConfigItem>
</otrs_config>
之后,您可以从OTRS GUI发布新的提供程序WebService,其中使用了新创建的连接器.
确保您传递了方法所需的所有参数!
$True = $LinkObject->LinkAdd(
SourceObject => 'Ticket',SourceKey => '321',Targetobject => 'FAQ',TargetKey => '5',Type => 'ParentChild',State => 'Valid',UserID => 1,);
更新:
请阅读此Document以了解如何构建通用接口,然后请添加新的连接器(LinkObject)
注册连接器及其操作 – 将XML文件放在/ Kernel / Config / Files / …
然后转到Sysconfig – > GenericInterface – > GenericInterface :: Operation :: ModuleRegistration并在GenericInterface :: Operation :: Module ### LinkObject :: LinkAdd旁边设置一个勾号并保存更改
然后将此Connector文件添加到/Custom/Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm
# --
# Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation backend
# copyright (C) 2016 ArtyCo (Artjoms Petrovs),http://artjoms.lv/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details,see
# the enclosed file copYING for license information (AGPL). If you
# did not receive this file,see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::GenericInterface::Operation::LinkObject::LinkAdd;
use strict;
use warnings;
use Kernel::GenericInterface::Operation::Common;
use Kernel::System::LinkObject;
use Kernel::System::VariableCheck qw(IsstringWithData IsHashRefWithData);
=head1 NAME
Kernel::GenericInterface::Operation::LinkObject::LinkAdd - GenericInterface Link Create Operation backend
=head1 SYnopSIS
=head1 PUBLIC INTERFACE
=over 4
=cut
=item new()
usually,you want to create an instance of this
by using Kernel::GenericInterface::Operation->new();
=cut
sub new {
my ( $Type,%Param ) = @_;
my $Self = {};
bless( $Self,$Type );
# check needed objects
for my $Needed (
qw(DebuggerObject ConfigObject MainObject logobject TimeObject DBObject EncodeObject WebserviceID)
)
{
if ( !$Param{$Needed} ) {
return {
Success => 0,ErrorMessage => "Got no $Needed!"
};
}
$Self->{$Needed} = $Param{$Needed};
}
# create additional objects
$Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
$Self->{LinkObject}
= Kernel::System->LinkObject->new( %{$Self} );
return $Self;
}
=item Run()
Create a new link.
my $Result = $OperationObject->Run(
Data => {
SourceObject => 'Ticket',Targetobject => 'Ticket',TargetKey => '12345',},);
$Result = {
Success => 1,# 0 or 1
ErrorMessage => '',# In case of an error
Data => {
Result => 1,# 0 or 1
},};
=cut
sub Run {
my ( $Self,%Param ) = @_;
# check needed stuff
if ( !IsHashRefWithData( $Param{Data} ) ) {
return $Self->{CommonObject}->ReturnError(
ErrorCode => 'LinkAdd.MissingParameter',ErrorMessage => "LinkAdd: The request is empty!",);
}
my $LinkID = $Self->{LinkObject}->LinkAdd(
%Param,);
if ( !$LinkID ) {
return $Self->{CommonObject}->ReturnError(
ErrorCode => 'LinkAdd.AuthFail',ErrorMessage => "LinkAdd: Authorization failing!",);
}
return {
Success => 1,Data => {
Result => $LinkID,};
}
1;
=back
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details,see
the enclosed file copYING for license information (AGPL). If you
did not receive this file,see L<http://www.gnu.org/licenses/agpl.txt>.
=cut
然后它应该出现,可以从管理员使用 – > Web服务 – >可用操作下拉列表当然可以用作Web服务.
PHP使用示例如下所示:
#### Initialize new client session ####
$client = new SoapClient(
null,array(
'location' => $url,'uri' => "Core",'trace' => 1,'login' => $username,'password' => $password,'style' => SOAP_RPC,'use' => SOAP_ENCODED
)
);
#### Create and send the SOAP Function Call ####
$success = $client->__soapCall("dispatch",array($username,$password,"LinkObject","LinkAdd","SourceObject",'Ticket',"SourceKey",$ticket_id1,"Targetobject","TargetKey",$ticket_id2,"Type",'ParentChild',"State",'Valid',"UserID",'1'
));
如果出现错误 – 启用调试,请查看系统日志并检查OTRS的所有初始设置
祝你好运!
更新#2
要注册Web服务 – 按“添加新的Web服务”按钮,根据需要对其进行命名并设置以下设置(选择LinkAdd操作)并保存
更新#3
这是OTRS 5的更新模块文件
# --
# Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation backend
# copyright (C) 2016 ArtyCo (Artjoms Petrovs),$Type );
# check needed objects
for my $Needed (
qw( DebuggerObject WebserviceID )
)
{
if ( !$Param{$Needed} ) {
return {
Success => 0,ErrorMessage => "Got no $Needed!"
};
}
$Self->{$Needed} = $Param{$Needed};
}
# create additional objects
$Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
$Self->{LinkObject}
= $Kernel::OM->Get('Kernel::System::LinkObject');
return $Self;
}
=item Run()
Create a new link.
my $Result = $OperationObject->Run(
Data => {
SourceObject => 'Ticket',see L<http://www.gnu.org/licenses/agpl.txt>.
=cut