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 => 'johndoe@nowhere.com',

            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 Service Core 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 => 'johndoe@nowhere.com',

            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 => 'johndoe@nowhere.com',

            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 => 'johndoe@nowhere.com',

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

}

 

 

 

 

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