# Perl script to dump API response-\>result

**URL:** <https://community.f5.com/t/perl-script-to-dump-api-response-result/8481>\
**Category:** Technical Forums\
**Tags:** icontrol, dev, devops\
**Created:** [February 16, 2010, 10:45pm UTC](https://community.f5.com/t/perl-script-to-dump-api-response-result/8481 "2010-02-16T22:45:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derek\_21893](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Derek\_21893](https://community.f5.com/u/Derek_21893)\
**Post date:** [February 16, 2010, 10:45pm UTC](https://community.f5.com/t/perl-script-to-dump-api-response-result/8481/1 "2010-02-16T22:45:50Z")

</div>

I’m sure I’m not the only one who has fun trying to figure out the sometimes massive data structures returned by an iControl API response. I’ve written a simple Perl program to dump the response for you using Data::Dumper.

You’ll need iControlTypeCast.pm in the same directory as this script.

Other module requirements:

SOAP::Lite

GetOpt::Long

Data::Dumper

MIME::Base64

You can edit the variables at the beginning of the script to match your installation, such that you do not have to specify a bunch of cmd line args every time. I just point them at my lab F5 device.

Hope this helps someone, Joe, maybe this could be included in the sample Perl scripts in a future API release?

Thanks,

-Derek

```tcl
!/usr/bin/perl -w  
    
   icontrol-dump  
   using Data::Dumper, dump the contents of an API response->result  
    
   written by Derek Andree derek.andree@gmail.com  
    
    
  use strict;  
  use Data::Dumper;  
  use Getopt::Long;  
  use SOAP::Lite;  
  use MIME::Base64;  
    
  require iControlTypeCast;  
    
   options, set for default behavior for your network if you like  
   this will let you not have to use command line args  
  my $ip = 0; management ip of an F5  
  my $proto = "https"; protocol, either http or https  
  my $port = 443; port to connect to   
  my $user = ""; username to connect as  
  my $pass = ""; password  
  my $urn = ""; iControl URN  
  my $method = ""; method to use  
  my $help = 0;  
    
  my $opts = GetOptions (  
  "ip=s" => \$ip,  
  "proto=s" => \$proto,  
  "port=i" => \$port,  
   "user=s" => \$user,  
   "pass=s" => \$pass,  
   "urn=s" => \$urn,  
    "method=s" => \$method,  
   "h" => \$help,  
   "help" => \$help  
   );  
    
  if ($help) {  
  &usage;  
  }  
    
  unless ($ip) {  
  print "Must specify an IP address!\n";  
  &usage;  
  }  
    
  unless ($proto) {  
  print "Must specify a protocol, either http or https!\n";  
  &usage;  
  }  
    
  unless ($port) {  
  print "Must specify a port number!\n";  
  &usage;  
  }  
    
  unless ($user) {  
  print "Need a username to connect with, try --user blah\n";  
  &usage;  
  }  
    
  unless ($pass) {  
  print "No password given, try --pass somepAssWord\n";  
  &usage;  
  }  
    
  unless ($urn) {  
  print "Must have an iControl URN\n";  
  &usage;  
  }  
    
  unless ($method) {  
  print "No method specified, don't know what I'm doing.\n";  
  &usage;  
  }  
    
  my $obj = SOAP::Lite->uri("urn:iControl:$urn")  
  ->proxy("$proto://$ip:$port/iControl/iControlPortal.cgi");  
    
  $obj->transport->http_request->header  
        (  
        'Authorization' =>  
         'Basic ' . MIME::Base64::encode("$user:$pass", ''),  
         );  
    
  my $response = $obj->$method;  
    
  &check_response($response);  
    
  print Dumper($response->result);  
    
  sub usage {  
  print "usage: icontrol-dump [--urn Urn/Name] [--ip ip_address]\n";  
  print " [--proto http|https] [--port port]\n";  
  print " [--user username] [--pass password]\n";  
  print " [--method method_name]\n";  
  print "example:\n";  
  print "./icontrol-dump --ip 10.10.10.10 --user fred --pass 123 \\\n";  
  print " --urn System/SystemInfo --method get_cpu_metrics\n";  
  exit;  
  }  
    
  sub check_response {  
    
    my $response = shift;  
    
    if ($response->fault) {  
      my $msg = $response->faultcode . " : " . $response->faultstring;  
      die $msg;  
    }  
  }

```

---

<div class="post-metadata">

**Author:** ![JRahm](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/jrahm/32/3327_2.png) [@JRahm](https://community.f5.com/u/JRahm)\
**Post date:** [February 18, 2010, 3:21pm UTC](https://community.f5.com/t/perl-script-to-dump-api-response-result/8481/2 "2010-02-18T15:21:04Z")

</div>

This is great, Derek! Mind if I add this to the wiki?

---

<div class="post-metadata">

**Author:** ![Derek\_21893](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Derek\_21893](https://community.f5.com/u/Derek_21893)\
**Post date:** [February 18, 2010, 5:35pm UTC](https://community.f5.com/t/perl-script-to-dump-api-response-result/8481/3 "2010-02-18T17:35:25Z")

</div>

By all means, feel free to add it to the wiki!
