Tag: REST

Using the Cloud Office Control Panel API from PowerShell — 2016 Edition

PowerShell CloudIn a post from last year, Steven Swenson explained how to use the Invoke-RestMethod cmdlet in PowerShell to query the Cloud Office REST API.

Since that time, I published Invoke-RsCloudOfficeRequest, a PowerShell module that takes all the work out of interacting with the Rackspace Cloud Office REST API.  It handles:

  • Passing the authentication header
  • Encoding PowerShell input into the expected body format
  • Parsing error responses into a meaningful format
  • Unpaginating paged responses
  • Storing API credentials so you don’t have to type them in every time (Optional)

But enough talk, let’s learn how to use it. Continue reading

Share and Enjoy

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

Choosing an HTTP Status Code — Stop Making It Hard

What could be simpler than returning HTTP status codes? Did the page render? Great, return 200. Does the page not exist? That’s a 404. Do I want to redirect the user to another page? 302, or maybe 301.

Life is bliss, well… until someone tells you you’re not doing this REST thing. Next thing you know, you can’t sleep at night because you need to know if your new resource returns the RFC-compliant, Roy-Fielding-approved status code. Is it just a 200 here? Or should it really be a 204 No Content? No, definitely a 202 Accepted… or is that a 201 Created?

What complicates matters is that the official HTTP/1.1 guidelines — the RFC — was originally written in 1997. That’s the year you went surfing the cyberweb in Netscape Navigator on your 33.6kbps modem. It’s a little like trying to apply Sun Tzu’s Art of War to modern business strategy. Timeless advice, to be sure, but I haven’t yet figured out how The Five Ways to Attack With Fire are going to help me do market validation. Continue reading

Share and Enjoy

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

Using the Cloud Office Control Panel API from PowerShell

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

© 2017 Racksburg

Theme by Anders NorenUp ↑