You are here: Chapter 11: FootPrints API > FootPrints Web Services API > Sample Code > Perl Sample

Perl Sample

Creating an Issue

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://fakeserver.phoneycompany.com/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl' );

}

my $soapenv = $soap->MRWebServices__createIssue(

    'WebServices',

    'fakepassword',

    '',

    {

        projectID => 78,

        title => 'Place title of new issue here.',

        assignees => ['user1', 'user2'],

        priorityNumber => 1,

        status => 'Open',

        description => "Place issue description here.\nFrom PERL code.",

        abfields =>

        {

            Last__bName => 'Doe',

            First__bName => 'John',

            Email__baddress => '[email protected]',

            Custom__bAB__bField__bOne => 'Value of Custom AB Field One'

        },

        projfields =>

        {

            Custom__bField__bOne => 'Value of Custom Field One',

            Custom__bField__bTwo => 'Value of Custom Field Two'

        }

    }

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

print "Issue $result has been created.\n";

Editing an Issue

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://fakeserver.phoneycompany.com/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl' );

}

my $soapenv = $soap->MRWebServices__editIssue(

    'WebServices',

    'fakepassword',

    '',

    {

        projectID => 78,

        mrID => 44,

        title => 'NEW title is here.',

        abfields =>

        {

            Custom__bAB__bField__bOne => 'NEW VALUE FOR Custom AB Field One'

        },

        projfields =>

        {

            Custom__bField__bTwo => 'NEW VALUE FOR Custom Field Two'

        }

    }

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

print "done\n";

Retrieving Issue Details

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://fakeserver.phoneycompany.com/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl' );

}

my $soapenv = $soap->MRWebServices__getIssueDetails(

    'WebServices',

    'fakepassword',

    '',

    78,

    1

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

my %hash = %{$result};

foreach my $item ( keys %hash )

{

    print "---\n";

    print "ITEM IS: [$item]\n";

    

    print "---\n";

    print $hash{$item};

    print "\n";

    

    print "---\n";

}

Querying the FootPrints Database

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://fakeserver.phoneycompany.com/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://fakeserver.phoneycompany.com/MRcgi/MRWebServices.pl' );

}

my $soapenv = $soap->MRWebServices__search(

    'WebServices',

    'fakepassword',

    '',

    "select mrID, mrTITLE from MASTER78 WHERE mrTITLE LIKE '%of%'"

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

my @result_list = @{$result};

for( my $i = 0; $i <= $#result_list; $i++ )

{

    print "RESULT $i\n";

    

    my $hash_ref = $result_list[$i];

    

    foreach my $item ( keys %{$hash_ref} )

    {

        my $val = $hash_ref->{$item};

        

        print "$item = '$val'\n";

    }

    

    print "---------------------\n";

}

Linking Issues

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://yourFootPrintsServer/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://yourFootPrintsServer/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://yourFootPrintsServer/MRcgi/MRWebServices.pl' );

}

# By calling this, you don't need to worry about whether this is a new or edited contact. This method

# will do all the work.

my $soapenv = $soap->MRWebServices__linkIssues(

    'dpinkowitz',

    'root',

    undef,

    {

        linkType => 'dynamic',

        issue1 => {projectID => 1, mrID => 1},

        issue2 =>  {projectID => 2, mrID => 5},

    }

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

print "Link is successful.\n" if $result;

Creating a Contact

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://yourFootPrintsServer/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://yourFootPrintsServer/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://yourFootPrintsServer/MRcgi/MRWebServices.pl' );

}

my $soapenv = $soap->MRWebServices__createContact(

    'WebServices',

    'root',

    '',

    {

        abNumber => 78,

        abfields =>

        {

            Last__bName => 'Doe',

            First__bName => 'John',

            Email__baddress => '[email protected]',

            Custom__bAB__bField__bOne => 'Value of Custom AB Field One'

        },

    }

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

print "Contact $result has been created.\n";

Editing a Contact

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://yourFootPrintsServer/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://yourFootPrintsServer/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://yourFootPrintsServer/MRcgi/MRWebServices.pl' );

}

my $soapenv = $soap->MRWebServices__editContact(

    'WebServices',

    'root',

    '',

    {

        abNumber => 78,

        abID => 44,  # can leave this out so long as the primary key field has a value; must use this if editing name of primary key value

        abfields =>

        {

            Last__bName => 'Doe',

            First__bName => 'John',

            Email__baddress => '[email protected]',

            Custom__bAB__bField__bOne => 'Value of Custom AB Field One'

        },

    }

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

print "Contact $result has been edited.\n";

Creating or Editing a Contact

use strict;

use SOAP::Lite;

my $USE_PROXY_SERVER = 1;

my $soap = new SOAP::Lite;

$soap->uri( 'http://yourFootPrintsServer/MRWebServices' );

if( $USE_PROXY_SERVER )

{

    $soap->proxy(

        'http://yourFootPrintsServer/MRcgi/MRWebServices.pl',

        proxy => ['http' => 'http://localhost:8888/'] );

}

else

{

    $soap->proxy( 'http://yourFootPrintsServer/MRcgi/MRWebServices.pl' );

}

# By calling this, you don't need to worry about whether this is a new or edited contact. This method

# will do all the work.

my $soapenv = $soap->MRWebServices__createOrEditContact(

    'WebServices',

    'root',

    '',

    {

        abNumber => 78,

        abfields =>

        {

            Last__bName => 'Doe',

            First__bName => 'John',

            Email__baddress => '[email protected]',

            Custom__bAB__bField__bOne => 'Value of Custom AB Field One'

        },

    }

);

my $result;

if( $soapenv->fault )

{

    print ${$soapenv->fault}{faultstring} . "\n";

    exit;

}

else

{

    $result = $soapenv->result;

}

print "Contact $result has been edited.\n";

Assigning individual Agents, Agents as Team members, and Teams

An 'assignees' key is available for the extraInfo parameter of the createIssue and editIssue Web API SOAP calls which is used for assigning or reassigning agents to an Issue. Agent assignment to an Issue is based on the order of Agents and Teams in the list applied to this 'assignees' key for the createIssue and editIssue Web API SOAP calls:

Assigning Agents

Agents which are not preceded by a Team name are assigned as individual agents regardless of team membership:

 'assignees' => [ 'individual_agent1', 'agent1_Team1', 'agentN_TeamK' ],

In this case, individual_agent1, agent1_Team1, and agentN_TeamK will be assigned as individual agents.

Assigning Agents as Team members

Agents preceded by Team name will be assigned as Team members:

 'assignees' => [ 'TeamK', 'agent1_TeamK'],

In this case, agent1_TeamK will be assigned as a member of TeamK.

 'assignees' => [ 'individual_agent1', 'agentN_TeamK', 'Team1', 'agent1_Team1', 'agent2_Team1', 'TeamK', 'agent1_TeamK', 'agent2_TeamK' ],

In this case, individual_agent1 and agentN_TeamK will be assigned as individuals, agent1_Team1 and agent2_Team1 will be assigned as members of Team1, and agent1_TeamK and agent2_TeamK will be assigned as members of TeamK.

Assigning Teams

Teams which are not followed by agents will be assigned based on team properties, i.e. to a team, selected agents, all members, or round robin base:

'assignees' => [ 'TeamL', 'TeamN' ],

Both teams (TeamL and TeamN) will be assigned based on their properties - to a team, selected

agents, all members or round robin base.

'assignees' => [ 'individual_agent1', 'agentN_TeamK', 'Team1', 'agent1_Team1', 'agent2_Team1', 'TeamK', 'agent1_TeamK', 'agent2_TeamK', 'TeamL', 'TeamN' ],

In this case, individual_agent1 and agentN_TeamK will be assigned as individuals, agent1_Team1 and agent2_Team1 will be assigned as members of Team1, agent1_TeamK and agent2_TeamK will be assigned as members of TeamK, and TeamL and TeamN will be assigned based on team properties - to a team, selected agents, all members, or round robin base.

Unassigning Agents

To unassign all agents, form an Issue using the editIssue Web API SOAP call. An empty list should be passed to the 'assignees' key of the extraInfo parameter:

'assignees' => [],

If the 'assignees' key of the externalInfo parameter is not defined, the assignees defined for an Issue remain unchanged.

Creating a CI

use strict;

 

my $soapUser = 'admin';

my $soapPass = 'root';

my $baseUrl = 'http://pyxis';

 

###################################################

###################################################

###################################################

 

use SOAP::Lite;

my $soap = new SOAP::Lite;

$soap->uri( $baseUrl . '/MRWebServices' );

$soap->proxy( $baseUrl . '/MRcgi/MRWebServices.pl' );

 

my $cmdb_id = 3;

my $ci_type_id = 10;

my $status = 'Active';

my $submit_user;

my $submit_systimestamp;

my $submit_usertimestamp;

my $lastedit_usertimestamp;

my $revision_usertimestamp;

my %attributes = (

x_float => 456.78,

x_int => 999

);

 

my $soapCall = $soap->MRWebServices__createCI(

$soapUser,

$soapPass,

'', # extra info

{

CMDB_ID => $cmdb_id,

CI_TYPE_ID => $ci_type_id,

STATUS => $status,

SUBMIT_USER => $submit_user,

SUBMIT_SYSTIMESTAMP => $submit_systimestamp,

SUBMIT_USERTIMESTAMP => $submit_usertimestamp,

LASTEDIT_USERTIMESTAMP => $lastedit_usertimestamp,

REVISION_USERTIMESTAMP => $revision_usertimestamp,

ATTRIBUTES => \%attributes,

}

);

if (1)

{

use Data::Dumper;

print Dumper($soapCall);

}

 

if( $soapCall->fault )

{

print ${$soapCall->fault}{faultstring} . "\n";

}

Edit a CI

use strict;

 

my $soapUser = 'admin';

my $soapPass = 'root';

my $baseUrl = 'http://pyxis';

 

###################################################

###################################################

###################################################

 

use SOAP::Lite;

my $soap = new SOAP::Lite;

$soap->uri( $baseUrl . '/MRWebServices' );

$soap->proxy( $baseUrl . '/MRcgi/MRWebServices.pl' );

 

my $cmdb_id = 3;

my $ci_id = 49;

my $ci_type_id = 10;

my $status = 'Retired';

my %attributes = (

x_int => 777

);

 

my $soapCall = $soap->MRWebServices__editCI(

$soapUser,

$soapPass,

'', # extra info

{

CMDB_ID => $cmdb_id,

CI_ID => $ci_id,

CI_TYPE_ID => $ci_type_id,

STATUS => $status,

ATTRIBUTES => \%attributes,

}

);

if (1)

{

use Data::Dumper;

print Dumper($soapCall);

}

 

if( $soapCall->fault )

{

print ${$soapCall->fault}{faultstring} . "\n";

}

Create a CI Relationship

use strict;

 

my $soapUser = 'admin';

my $soapPass = 'root';

my $baseUrl = 'http://pyxis';

 

###################################################

###################################################

###################################################

 

use SOAP::Lite;

my $soap = new SOAP::Lite;

$soap->uri( $baseUrl . '/MRWebServices' );

$soap->proxy( $baseUrl . '/MRcgi/MRWebServices.pl' );

 

my $cmdb_id = 3;

my $relation_cfg_id = 2;

my $from_ci_id = 49;

my $from_ci_type = 10;

my $to_ci_id = 51;

my $to_ci_type = 10;

 

my $soapCall = $soap->MRWebServices__createCIRelation(

$soapUser,

$soapPass,

'', # extra info

{

CMDB_ID => $cmdb_id,

RELATION_CFG_ID => $relation_cfg_id,

FROM_CI_ID => $from_ci_id,

TO_CI_ID => $to_ci_id,

FROM_CI_TYPE => $from_ci_type,

TO_CI_TYPE => $to_ci_type,

}

);

 

if (1)

{

use Data::Dumper;

print Dumper($soapCall);

}

 

if( $soapCall->fault )

{

print ${$soapCall->fault}{faultstring} . "\n";

}

Link a Contact to a CI

use strict;

 

my $soapUser = 'admin';

my $soapPass = 'root';

my $baseUrl = 'http://pyxis';

 

###################################################

###################################################

###################################################

 

use SOAP::Lite;

my $soap = new SOAP::Lite;

$soap->uri( $baseUrl . '/MRWebServices' );

$soap->proxy( $baseUrl . '/MRcgi/MRWebServices.pl' );

 

my $cmdb_id = 3;

my $ci_id = 49;

my $ci_type_id = 10;

my $abnumber = 2;

my $abid = 1;

my $soapCall = $soap->MRWebServices__createCIContactLink(

$soapUser,

$soapPass,

'', # extra info

{

CMDB_ID => $cmdb_id,

CI_ID => $ci_id,

CI_TYPE_ID => $ci_type_id,

ABNUMBER => $abnumber,

ABID => $abid,

}

);

 

if (1)

{

use Data::Dumper;

print Dumper($soapCall);

}

 

if( $soapCall->fault )

{

print ${$soapCall->fault}{faultstring} . "\n";

}

 

Link an Issue to a CI

use strict;

 

my $soapUser = 'admin';

my $soapPass = 'root';

my $baseUrl = 'http://pyxis';

 

###################################################

###################################################

###################################################

 

use SOAP::Lite;

my $soap = new SOAP::Lite;

$soap->uri( $baseUrl . '/MRWebServices' );

$soap->proxy( $baseUrl . '/MRcgi/MRWebServices.pl' );

 

my $cmdb_id = 3;

my $ci_id = 49;

my $ci_type_id = 10;

my $projectid = 2;

my $mrid = 19;

my $soapCall = $soap->MRWebServices__createCIIssueLink(

$soapUser,

$soapPass,

'', # extra info

{

CMDB_ID => $cmdb_id,

CI_ID => $ci_id,

CI_TYPE_ID => $ci_type_id,

PROJECTID => $projectid,

MRID => $mrid,

}

);

 

if (1)

{

use Data::Dumper;

print Dumper($soapCall);

}

 

if( $soapCall->fault )

{

print ${$soapCall->fault}{faultstring} . "\n";

}