Is there an example of how to use Perl SOAP::Lite to create a request in CA Service Desk Manager (CA SDM) via SOAP Web Services?

Document ID : KB000019504
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

This document provides a sample piece of code of how to use Perl SOAP::Lite to create a request in CA Service Desk Manager (CA SDM) via SOAP Web Services.

NOTE: This is offered with no guarantees and is not supported by CA Support.

Solution:

#!/usr/local/bin/perl
 
#use SOAP::Lite trace=>'debug';
use SOAP::Lite;
use Data::Dumper;
use XML::Simple;
#use strict;
#use warnings;
use Getopt::Std;
# Declare Constants
use constant DEBUG      => 0;           # DEBUG settings
use constant CONSOLE    => 0;           # CONSOLE DEBUG settings
 
 
if ($#ARGV < 4 ) {
 print "usage: <script> username password incident/request 'Summary' 'description'\n";
 exit;
}
################################################################
# UPDATE WITH YOUR SPECIFIC USERNAME AND PASSWORD (or take command line args)
################################################################
my $username = $ARGV[0];
my $password = $ARGV[1];
my $tickettype = "crt:180";
 
print "\nArgument 2 = $ARGV[2]\n";
if($ARGV[2] eq 'incident') {
$tickettype = "crt:182";
print "\nTicket Type Handle = $tickettype\n";
}
else {
$tickettype = "crt:180";
}
 
#my $ticketsummary = $ARG[3];
#my $ticketdesc = $ARG[4];
 
# Declare Variables
my $xml = new XML::Simple;
my $ticket_number;
my $ticket_handle;
my $wsdl = 'http://yourServiceDeskServer:8080/axis/services/USD_R11_WebService?wsdl';
 
my $service = SOAP::Lite->service($wsdl);
 
my $sid = $service->login($username, $password);
 
my $userHandle = $service->getHandleForUserid($sid,$user);
my $method = SOAP::Data->name('createRequest');
 
my @params = (SOAP::Data->name("sid" => $sid),
SOAP::Data->name("userHandle" => $userHandle),
SOAP::Data->name("attrVals" =>
  \SOAP::Data->value(
   SOAP::Data->name("string" => "description"),
   SOAP::Data->name("string" => $ARGV[4]),
   SOAP::Data->name("string" => "customer"),
   SOAP::Data->name("string" => "cnt:25236A9BAEC3084CA149BB5F52A97DC4"),
   SOAP::Data->name("string" => "type"),
                SOAP::Data->name("string" => $tickettype),
                SOAP::Data->name("string" => "category"),
   SOAP::Data->name("string" => "pcat:5103"),
   SOAP::Data->name("string" => "assignee"),
  SOAP::Data->name("string" => ""),
   SOAP::Data->name("string" => "group"),
   SOAP::Data->name("string" => "cnt:F8C6AF99927B5C4683ACA0A2B3C3B7C7"),
   SOAP::Data->name("string" => "summary"),
   SOAP::Data->name("string" => $ARGV[3])
  )
),
SOAP::Data->name("propertyValues" =>
  \SOAP::Data->value(
   SOAP::Data->name("string" => '')
  )
),
SOAP::Data->name("template" => ''),
SOAP::Data->name("attributes" =>
  \SOAP::Data->value(
   SOAP::Data->name("string" => 'ref_num'),
   SOAP::Data->name("string" => 'persistent_id')
  )
),
SOAP::Data->name("newRequestHandle"),
SOAP::Data->name("newRequestNumber")
);
 
print "dumper: ".Dumper(\@params)."\n" if (DEBUG);
 
my $soap = $service->call($method => @params);
 
if ($soap->fault){
        print "Error\n";
        print "[".$soap->faultcode."] [".$soap->faultstring."] [".$soap->faultdetail."]";
} else {
        print $soap->result if (DEBUG);
}
 
print "SOAP dump: ".Dumper($soap->result)."\n" if (DEBUG);
 
$xml = XMLin($soap->result);
 
$ticket_number = $xml->{Attributes}->{Attribute}->[0]->{AttrValue};
$ticket_handle = $xml->{Attributes}->{Attribute}->[1]->{AttrValue};
 
print "Ticket Number = $ticket_number\n";
print "Ticket Handle = $ticket_handle\n";
 
$service->logout($sid);
 
exit;