Here is a quick script on how to login to ServiceMesh AgilityPlatform. Never heard of the product? don’t bother. It works nevertheless …

function Enter-AgilityPlatform {
  [Parameter(Mandatory = $false, Position = 0)]
  [Uri] $UriBase = ''
  [Parameter(Mandatory = $true)]
  [PSCredential] $Credential
$OutputParameter = $null;
try {
  [Uri] $UriLogin = ("{0}j_spring_security_check" -f $UriBase.AbsoluteUri)
  $Body = 'product={0}&j%5Fusername={1}&j%5Fpassword={2}' 
    -f 'AgilityPlatform', [System.Web.HttpUtility]::UrlEncode($cred.Username), 
  $r = Invoke-RestMethod -Uri $UriLogin -Method POST -SessionVariable s 
    -Body $Body -ContentType 'application/x-www-form-urlencoded';

  $r = Invoke-RestMethod -Uri ("{0}connection" -f $Uri.AbsoluteUri ) -WebSession $s;
  if($r) {
    $OutputParameter = $s;
  } # if
} # try
catch {
  Write-Error ("Login to '{0}' with Username '{1}' FAILED [{2}]." 
    -f $UriBase, $cred.Username, $_)
} # catch
finally {
  # Cleanup
  # N/A
} # finally
return $OutputParameter;
} # function

Subsequent calls to AgilityPlatform are then execeuted like this (eg list all projects on the platform):

# User to login
$cred = Get-Credential "UberAdmin";
# Specify base URI
[Uri] $UriBase = ''
# Select API version
[Uri] $Uri = "{0}api/current/" -f $UriBase.AbsoluteUri;
$s = Enter-AgilityPlatform -UriBase $UriBase -Credential $cred;
$r = Invoke-RestMethod -Uri ("{0}project" -f $Uri.AbsoluteUri ) -WebSession $s;

An easy way to check if the login session is still valid is to issue the following request:

$r = Invoke-RestMethod -Uri ("{0}connection" -f $Uri.AbsoluteUri ) -WebSession $s;

You should receive a namespace in ‘ns1’ like ‘’ or an exception if the login session is already expired.

If you happen to get an exception upon using UrlEncode() make sure you issue the following statement in your PowerShell session first:

Add-Type -AssemblyName System.Web;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.