LinkAdd - pyOTRS ResponseParseError

Moderator: crythias

Post Reply
hypex
Znuny newbie
Posts: 10
Joined: 14 Jul 2010, 08:19
Znuny Version: OTRS5

LinkAdd - pyOTRS ResponseParseError

Post by hypex »

Hi everyone

For reference I have been following this guide. viewtopic.php?t=42070 and I'm running Znuny 6.4.3

I am using pyOTRS library and have the web service running to call LinkAdd.

I can make the call, and it links the ticket, but I get a parse error on the return response that then breaks the script.

Any ideas?

pyOTRS error

Code: Select all

Traceback (most recent call last):
  File "C:\scripts\ZnunyCreateBulkTickets\run.py", line 76, in <module>
    res = client.link_add(new_ticket_id,new_parent_ticket_id)
  File "C:\Program Files\Python310\lib\site-packages\pyotrs\lib.py", line 1742, in link_add
    return self._parse_and_validate_response(self._send_request(payload))
  File "C:\Program Files\Python310\lib\site-packages\pyotrs\lib.py", line 2196, in _parse_and_validate_response
    raise ResponseParseError("Unknown key in response JSON DICT!")
pyotrs.lib.ResponseParseError: Unknown key in response JSON DICT!
Debug Information

Code: Select all

$VAR1 = {
  'SessionID' => 'kbUNsqbKVJtrtf<removed>',
  'SourceKey' => 146847,
  'SourceObject' => 'Ticket',
  'State' => 'Valid',
  'TargetKey' => 146846,
  'TargetObject' => 'Ticket',
  'Type' => 'Normal'
};

Outgoing data before mapping (<remove>, debug)
$VAR1 = {
  'Result' => 1
};
Returning provider data to remote system (HTTP Code: 200) (<removed>, debug)
{"Result":1}
Steps taken to load code

Created GenericInterfaceLinkObjectConnector.xml in /opt/otrs/Kernel/Config/Files/XML/.

Code: Select all


<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="2.0" init="Application">
    <Setting Name="GenericInterface::Operation::Module###LinkObject::LinkAdd" Required="0" Valid="1">
        <Description Translatable="1">GenericInterface module registration for the operation layer.</Description>
        <Navigation>GenericInterface::Operation::ModuleRegistration</Navigation>
        <Value>
            <Hash>
                <Item Key="Name">LinkAdd</Item>
                <Item Key="Controller">LinkObject</Item>
                <Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item>
            </Hash>
        </Value>
    </Setting>
</otrs_config>

created LinkAdd.pm in /Kernel/GenericInterface/Operation/LinkObject/

Code: Select all


# --
# Copyright (C) 2019–present Efflux GmbH, https://efflux.de/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --

package Kernel::GenericInterface::Operation::LinkObject::LinkAdd;

use strict;
use warnings;

use Kernel::System::LinkObject;
use Kernel::System::VariableCheck qw(IsStringWithData IsHashRefWithData);

use parent qw(
        Kernel::GenericInterface::Operation::Common
);

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};
        }

        return $Self;
}

=head2 Run()

    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) = @_;

        my ($UserID, $UserType) = $Self->Auth(%Param);

        return $Self->ReturnError(
                ErrorCode    => 'LinkAdd.AuthFail',
                ErrorMessage => "LinkAdd: Authorization failing!",
        ) if !$UserID;

        # Check needed parameters.
        for my $Needed (qw(SourceObject SourceKey TargetObject TargetKey Type State)) {
                if (!$Param{Data}->{$Needed}) {
                        return $Self->ReturnError(
                                ErrorCode     => 'LinkAdd.MissingParameter',
                                ErrorMessage => "LinkAdd: $Needed parameter is missing!",
                        );
                }
        }

        $Param{Data}->{UserID} = $UserID;  # Comment this out if you want to pass the UserID in your request.
        my $Success = $Kernel::OM->Get('Kernel::System::LinkObject')->LinkAdd(%{$Param{Data}});

        return {
                Success      => 1,
                ErrorMessage => '',                    # In case of an error. TODO: Add debugging if wanted.
                Data         => {
                        Result => $Success,  # 0 or 1
                },
        };
}

1;

Rebuild Config and Deleted Cache

Code: Select all

/opt/otrs/bin/otrs.Console.pl Maint::Cache::Delete
/opt/otrs/bin/otrs.Console.pl Maint::Config::Rebuild
Checked in Sys config -> GenericInterface::Operation::ModuleRegistration that LinkAdd is present.

Created Webservice GenericLinkConnectorREST

Code: Select all

---
Debugger:
  DebugThreshold: debug
  TestMode: '0'
Description: ''
FrameworkVersion: 6.4.3
Provider:
  Operation:
    LinkAdd:
      Description: ''
      IncludeTicketData: '0'
      Type: LinkObject::LinkAdd
  Transport:
    Config:
      AdditionalHeaders: ~
      KeepAlive: ''
      MaxLength: '100000000'
      RouteOperationMapping:
        LinkAdd:
          ParserBackend: JSON
          RequestMethod: []
          Route: /LinkAdd
    Type: HTTP::REST
RemoteSystem: ''
Requester:
  Transport:
    Type: ''

New to OTRS, any help given is me guessing
Post Reply