Accessing Secret Server programmatically - Perl sample script

Root > Secret Server > API - Web Services

For instructions with using Perl and Integrated Windows Authentication see:

Secret Server Webservices can be called using scripts. This example demonstrates how to authenticate and retrieve a secret programatically in Perl. There is also a more detailed PHP example script.

This is a working example for Secret Server Online; a test user infromation has been filled in and OrganizationCode passed in. The test user has been restricted to only viewing Secrets.

If connecting to an Installed instance change the url to match your site and pass in empty string for organizationCode.

This example runs using standard perl libs with our exact version being Strawberry Perl


use LWP::UserAgent;
use HTTP::Request;
use XML::Parser;

#Update these value to match your user settings and instance URL
my $username = "ThycoticTest";
my $password= "passwordt";
my $organizationCode= "RT9R";
my $domain = "";
my $WebServiceUrl = "";

# The main script calls
my $authtoken = GetToken($username ,$password,$organizationCode,$domain);
my $secretInXML = GetSecretLegacy($authtoken, "88395");
print $secretInXML;

# 1) Authentication Token
sub GetToken()
 my($username, $password, $organizationCode, $domain) = @_;
 my $url = $WebServiceUrl."/Authenticate?username=$username&password=$password&organization=$organizationCode&domain=$domain";
 my $response = WSRequest($url);
 my $token = "";
 if ($response->is_success){
  my $tokenXML = $response->content;
  if( $tokenXML =~ m/<Token>(.+)<\/Token>/)
   $token = $1;
  if($token eq "")
   die "Login failed";
  print $response->content;
 return $token;

# 2) Load a Secret

# Note: The SecretId can be found by going to the SecretView page and in the QueryString will be SecretId=#

sub GetSecretLegacy()
  my($token, $secretId) = @_;
  my $url = $WebServiceUrl."/GetSecretLegacy?token=". $token . "&secretId=" . $secretId;
  my $response = WSRequest($url);
  my $secret;
  if ($response->is_success){
   $secret = $response->content;
  return $secret;

sub WSRequest()
 my($url) = @_;
 my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30);
 my $header = HTTP::Request->new(GET => $url);
 my $request = HTTP::Request->new('GET', $url, $header);
 my $response = $agent->request($request);
 return $response;

Add Feedback