如何通过 OTRS 中的 Web 服务(SOAP 或 REST)将配置项链接/获取到工单 [英] How to Link / Get Config Item to a Ticket through Webservice (SOAP or REST) in OTRS

查看:12
本文介绍了如何通过 OTRS 中的 Web 服务(SOAP 或 REST)将配置项链接/获取到工单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何通过 SOAP 或 REST Web 服务获取票证并将其链接到配置项.我已经在管理控制台中导入了这个 Restfull Web service 和使用此 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.

我在谷歌上进行了大量搜索,发现票证可以通过 OTRS GUI 链接到配置项,并且会在 AgentTicketzoom 页面中显示,我希望这可以通过 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.

更新#1

我成功地将 web 控制器添加到我现有的票证连接器.网址是 http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject with POST Call.but 我收到这个错误

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":"Server","faultstring":"没有配置对象!"}

{"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

因此,对 (http://otrs_host/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/LinkAdd?UserLogin=login&Password=password) 和 json

So, making POST call to (http://otrs_host/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/LinkAdd?UserLogin=login&Password=password) with json

{"SourceObject":"Ticket","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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆