Sample PERL Display Pager ID, Last Name and First Name

Not Yet Reviewed

Please see below comments.

0

Comments

3 comments
Date Votes

Please sign in to leave a comment.

  • It did not copy the full copy/paste format, please ignore this post.

    0
  • Aris, this forum uses markdown, so you can wrap your code in triple backtics (`) to make a code block. I'm working on getting a link with some help on here.

    0
  • #!/usr/bin/perl
    {
    
    use LWP::UserAgent;
    
    my $ua = LWP::UserAgent->new;
    
    my $server_endpoint = "https://instance.xmatters.com/api/services/xmatters-5.5.47.xmatters-5.5.47HttpSoap12Endpoint/";
    
    # set custom HTTP request header fields
    my $req = HTTP::Request->new(POST => $server_endpoint);
    $req->header('content-type' => 'text/xml');
    
    # add POST data to HTTP request body
    my $post_data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.xmatters.com/webservices/schema#5.5.47">
       <soapenv:Header/>
       <soapenv:Body>
          <sch:FindPersons>
             <sch:user>soaptesting</sch:user>
             <sch:password>soaptesting</sch:password>
             <sch:clientTimestamp/>
             <sch:clientIP/>
             <sch:clientOSUser/>
             <sch:company/>
             <sch:searchParameters>
                <sch:targetName></sch:targetName>
             </sch:searchParameters>
          </sch:FindPersons>
       </soapenv:Body>
    </soapenv:Envelope>';
    $req->content($post_data);
    
    my $resp = $ua->request($req);
    if ($resp->is_success) {
        use XML::LibXML;
    
        my $parser = XML::LibXML->new( );
        my $dom    = $parser->parse_string($resp->content);
        @person = $dom->getElementsByTagName ("ns:person");
        print STDOUT "Pager ID                  Name                 \n";
        print STDOUT "----------------------    -------------------- \n";
    
        my $i=0;
        foreach(@person){
        $targetName=$person[$i]->getElementsByTagName("ns:targetName");
        $lastName=$person[$i]->getElementsByTagName("ns:lastName");
        $firstName=$person[$i]->getElementsByTagName("ns:firstName");
        printf STDOUT "%-25s %s, %s\n", $targetName, $lastName, $firstName;
        $i=$i+1;
        }
    
    }
    else {
        print "HTTP POST error code: ", $resp->code, "\n";
        print "HTTP POST error message: ", $resp->message, "\n";
    }
    
    
    }
    
    0

Didn't find what you were looking for?

New post