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

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

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

Post by franceswong0129 » 23 Jan 2019, 11:40

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
OTRS guru
Posts: 4795
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

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

Post by reneeb » 23 Jan 2019, 12:00

You have to pass the values for the dynamic fields ProcessID and ActivityID
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

franceswong0129
OTRS newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
OTRS Version?: ITSM 6

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

Post by franceswong0129 » 24 Jan 2019, 03:12

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
OTRS wizard
Posts: 180
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6

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

Post by skullz » 26 Jan 2019, 14:51

1. You only can assign to one Activity ID
2. Transition/Transition Action is not dynamic field, hence no need to pass

franceswong0129
OTRS newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
OTRS Version?: ITSM 6

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

Post by franceswong0129 » 28 Jan 2019, 05:41

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
OTRS guru
Posts: 4795
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

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

Post by reneeb » 29 Jan 2019, 14:38

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 / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

skullz
OTRS wizard
Posts: 180
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6

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

Post by skullz » 30 Jan 2019, 05:32

Code: Select all

DynamicField => [
	 {
   	 Name     => "ProcessManagementProcessID",
   	 Value        => "Process-XXXX",
    	},
	{
   	 Name     => "ProcessManagementActivityID",
    	Value        => "Activity-XXXXX",
   	 },
],

franceswong0129
OTRS newbie
Posts: 12
Joined: 22 Jan 2019, 10:32
OTRS Version?: ITSM 6

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

Post by franceswong0129 » 04 Feb 2019, 06:41

Thank you so much for all your help !!!

Post Reply