[SOLVED]How to create process ticket through REST in OTRS 6

English! place to talk about development, programming and coding
Post Reply
franceswong0129
Znuny newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
Znuny Version: ITSM 6

[SOLVED]How to create process ticket through REST in OTRS 6

Post by franceswong0129 »

With my own perl script I know how to create a normal ticket with the help of Webservice. However we have added a process with multiple activities and transitions when we create a new ticket. Is that possible to create such a process ticket through REST ?The following is my code to create a normal ticket.

Code: Select all

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


my $CreateControllerAndRequest = '/Webservice/GenericTicketConnectorREST/Ticket';

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

}
Thank you !!
Last edited by franceswong0129 on 04 Feb 2019, 08:14, edited 1 time in total.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: How to create process ticket through REST in OTRS 6

Post by reneeb »

You have to pass the values for the dynamic fields ProcessID and ActivityID
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
franceswong0129
Znuny newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
Znuny Version: ITSM 6

Re: How to create process ticket through REST in OTRS 6

Post by franceswong0129 »

Dear reneeb,
I have tried to add the following code but it just create a normal ticket, is that wrong ?

Code: Select all

DynamicField => {
    ProcessEntityID  => 'Process-xxxxxx',
    ActivityEntityID  => 'Activity-xxxxxxx,Activity-xxxxxxx',
    TransitionEntityID => 'Transition-xxxxxxx,',
    TransitionActionEntityID => 'TransitionAction-xxxxxxx,TransitionAction-xxxxxxx,TransitionAction-xxxxxxx,TransitionAction-xxxxxxx',
    },
Thank you so much !!
skullz
Znuny superhero
Posts: 618
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: How to create process ticket through REST in OTRS 6

Post by skullz »

1. You only can assign to one Activity ID
2. Transition/Transition Action is not dynamic field, hence no need to pass
franceswong0129
Znuny newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
Znuny Version: ITSM 6

Re: How to create process ticket through REST in OTRS 6

Post by franceswong0129 »

I tried the following code.

Code: Select all

     DynamicField => {
        ProcessEntityID  => 'Process-xxxxxxxx',
        ActivityEntityID  => 'Activity-xxxxxxxx',
        (Name =>'EventName', Value => '123'),
        (Name => 'Organiser', Value=> '123'),
        (Name =>'EventStartDate', Value=> '2019-01-10'),
        (Name =>'EventEndDate', Value=> '2019-01-10'),
        (Name => 'Venue',Value => '123'),
        (Name =>'NatureofComplaint',Value => '123'),
        (Name =>'TypeofComplaint',Value =>'123'),
        (Name =>'FeedbackByComplainant',Value => '123'),
     }
Still failed to go through the process and we have our own assigned dynamic fields. Any ideas? Thank you so much !!
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: How to create process ticket through REST in OTRS 6

Post by reneeb »

Maybe look at the Webservice debugger... Open Webservices in admin area, select your webservice, then there's a 'debugger' button on the left... Select the request that produces the error. Maybe there's more information about what's going wrong.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
skullz
Znuny superhero
Posts: 618
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: How to create process ticket through REST in OTRS 6

Post by skullz »

Code: Select all

DynamicField => [
	 {
   	 Name     => "ProcessManagementProcessID",
   	 Value        => "Process-XXXX",
    	},
	{
   	 Name     => "ProcessManagementActivityID",
    	Value        => "Activity-XXXXX",
   	 },
],
franceswong0129
Znuny newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
Znuny Version: ITSM 6

Re: How to create process ticket through REST in OTRS 6

Post by franceswong0129 »

Thank you so much for all your help !!!
Post Reply