如何通过OTRS中的Web服务(SOAP或REST)将票证链接/获取配置项 [英] How to Link / Get Config Item to a Ticket through Webservice (SOAP or REST) in OTRS
问题描述
我想知道如何通过SOAP或REST Webservice获取票证并将其链接到Configuration项目. 我已在管理控制台中导入了 Restfull Web服务使用此URL成功创建并获取票证信息 http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/1 .
I want to know how to get and link the ticket to Configuration item through SOAP or REST Webservice. I have imported this Restfull Web service in admin console and successfully created and getting ticket information using this url http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/1.
但是问题是,当我获得故障单信息时,链接的配置项信息没有出现.
but the problem is the linked config item information is not coming when i get the ticket information.
我在Google上进行了大量搜索,发现票证可以通过OTRS GUI链接到Config Item,并且它将显示在AgentTicketzoom页面中,我希望这可以通过Web服务来完成. 任何人都可以帮助我解决这个问题,或建议一些有关如何创建Web服务以从故障单获取链接对象信息的文档.
i did lots of search on google found that ticket can be linked to Config Item through OTRS GUI and in AgentTicketzoom page it will show, i want this to be done through web service. can any one help me in this problem or suggest some doc on how to create web service to get linked object information from ticket.
Updated#1
Updated#1
我已将Web控制器成功添加到我现有的Ticket连接器中.网址为 http://XXX.XXX.XXX.带有POST调用的XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject ,但我遇到此错误
i added web controller to my existing Ticket connector successfully. the url is http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject with POST Call.but i am getting this error
{"faultcode":服务器","faultstring":没有ConfigObject!"}
{"faultcode":"Server","faultstring":"Got no 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};
推荐答案
经过大量工作,我找到了通过POST REST调用来实现的解决方案. 我的主要麻烦是要使用正确的%Param创建LinkObject. 因此,我已经实现了直接代码来获取对LinkAdd的正确调用. 主要是Artjoman提供了方法.但是我发现了一些错误,因此这是OTRS_HOME/Custom/Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm中的另一个perl模块:
After lot of work, i've found the solution to made it by POST REST call. My main trouble was about creating LinkObject with right %Param. So, i've implement direct code to aquire right call LinkAdd. Mainly, Artjoman provide the way. But i catch some errors on it, so here is another perl module in OTRS_HOME/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::System::ObjectManager;
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 WebserviceID )
)
{
if ( !$Param{$Needed} ) {
return {
Success => 0,
ErrorMessage => "Got no $Needed!"
};
}
$Self->{$Needed} = $Param{$Needed};
}
# create additional objects
local $Kernel::OM = Kernel::System::ObjectManager->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',
SourceKey => '321',
TargetObject => 'Ticket',
TargetKey => '12345',
Type => 'ParentChild',
State => 'Valid',
UserID => 1,
},
);
$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->ReturnError(
ErrorCode => 'LinkAdd.MissingParameter',
ErrorMessage => "LinkAdd: The request is empty!",
);
}
my $LinkID = $Self->{LinkObject}->LinkAdd(
'SourceKey' => $Param{Data}{SourceKey},
'SourceObject' => $Param{Data}{SourceObject},
'State' => $Param{Data}{State},
'TargetKey' => $Param{Data}{TargetKey},
'TargetObject' => $Param{Data}{TargetObject},
'Type' => $Param{Data}{Type},
'UserID' => $Param{Data}{UserID},
);
if ( !$LinkID ) {
return $Self->ReturnError(
ErrorCode => 'LinkAdd.AuthFail',
ErrorMessage => "LinkAdd: Authorization failing!",
);
}
return {
Success => 1,
Data => {
Result => $LinkID,
},
};
}
sub ReturnError {
my ( $Self, %Param ) = @_;
$Self->{DebuggerObject}->Error(
Summary => $Param{ErrorCode},
Data => $Param{ErrorMessage},
);
# return structure
return {
Success => 1,
ErrorMessage => "$Param{ErrorCode}: $Param{ErrorMessage}",
Data => {
Error => {
ErrorCode => $Param{ErrorCode},
ErrorMessage => $Param{ErrorMessage},
},
},
};
}
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
So, making POST call to (http://otrs_host/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/LinkAdd?UserLogin=login&Password=password) with json
{"SourceObject":票证","SourceKey":"7","TargetObject":"ITSMConfigItem","TargetKey":"1","Type":"DependsOn","State":有效," UserID:" 1}
{"SourceObject":"Ticket","SourceKey":"7","TargetObject":"ITSMConfigItem","TargetKey":"1","Type":"DependsOn","State":"Valid","UserID":"1"}
将在Ticket和ITSMConfigItem(而不是计算机,硬件等)之间创建一个链接. 我认为,这个简单而粗鲁的解决方案将有助于了解如何以一种更好的(但可行的)方式向您的REST OTRS添加完整的API操作.
will create a link between Ticket and ITSMConfigItem (not a computer, hardware and so on.) I think, this simple and quite rude solution will help to understand how to add a full-api operations to your REST otrs with a better(but working) way.
这篇关于如何通过OTRS中的Web服务(SOAP或REST)将票证链接/获取配置项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!