PowerShell as an interactive API playground

From time to time we encountered situations where we needed to test some API calls and though that interactive playground application would be a nice addition to our API tools. And recently we’ve found a perfect replacement – Windows PowerShell.

PowerShell 2.0 has added New-WebServiceProxy cmdlet to a set of tools, and that’s all you need to start playing with API. Open PowerShell console and type:

$api = New-WebServiceProxy -Uri https://www.teamdesk.net/secure/api/21995/service.asmx?WSDL

Now you can call API methods on $api variable. First method, of course, is Login()

$api.Login("anonymous@teamdesk.net", "")

And the next could be, for example


PowerShell will output

API Test

Let’s try Query()

$xml = $api.Query("SELECT TOP 1 [Text], [Date] FROM [Test]")

and see what’s inside


PowerShell output is

id   : 2
m    : true
d    : true
Text : Test 2
Date : 2001-01-01

If you prefer to have output in table like format, use Format-Table cmdlet

$xml.Data.r | Format-Table

id         m        d        Text                Date
--         -        -        ----                ----
2          true     true     Test 2              2001-01-01

And it’s not limited to queries only – you can call create/update operations as well.

$xml.Data.r.Text = "Test 1"
$api.Update("Test", $xml)


Tweet about this on TwitterShare on Facebook0Share on Google+0