Many don’t know that the Cloud Office Control Panel also has a REST API.  You can find the API documentation here.   Most of the functionality available in the web control panel is also available in the REST API.  In this blog post I’m going to walk through some PowerShell code that accesses the API.

In previous versions of PowerShell, users had to rely on the .NET framework and other secondary resources to use a REST API. However, v3 of Powershell includes a new cmdlet called Invoke-RestMethod.  There were some limitations in v3 specific to how you set headers, but v4 of PowerShell allows you to have full control over your request.  Be sure you’re using PowerShell v4 to run the examples below.

Of course the first thing we have to worry about is auth.  The REST API requires an X-Api-Signature header, which is compiled by the Get-XApiSignature function. That function requires your api key, secret, and the value of the User-Agent header.

The next file, ListDomains.ps1, gets the XApiSignature header value, builds a hash for all the headers, and then makes the call to Invoke-RestMethod to retrieve a list of domains from the API.  Invoke-RestMethod also parses the body of the response into an object (similar to how web-api works and is a huge time-saver!)  This allows us to pipe the result directly into Format-Table to display the list of domains in a readable format.

In part two we’ll get fancy and create a mailbox.


Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS