Not so long ago, I was able to acquire an Xbox 360 system from a friend and colleague. I have wanted one for awhile, but have never been able to justify the cost. I can’t begin to complain about the deal I got on this used system…it was pretty much a steal. Thanks, Dave!
Since it came out, my brother has been hounding me to get an Xbox 360 so that we can play the Halo games together. So, when I got this new (to me) system, he blessed me with my own copy of Halo 4 for my birthday. I have some other games that came with the system, but so far, Halo 4 has dominated my time as I am trying to get as many achievements as I can. Currently, I am trying to make it through the entire campaign on the “Legendary” level. I have also had fun with some of the co-operative games, competitions, and challenges. If you would like to look me up, my gamertag is jth1205.
This blog is a Powershell blog, so you might be wondering what an Xbox 360 has to do with Powershell. I’m glad you asked!
I have recently found a resource for an API that allows access to various Xbox profile information. This API can provide all kinds of information in a variety of formats. As it turns out, Powershell likes to eat some of these data formats for breakfast…JSON, XML, etc. The latest version of Powershell, version 3, has a new cmdlet called “Invoke-WebRequest” which will facilitate my examples here.
To start, head over to https://xboxapi.com to get some information on some of the acceptable requests. You can get information on profiles, friends, games, and achievements. To start, I am going to use my gamertag to show you how to get some information about a specific user from the service.
Invoke-WebRequest -URI https://xboxapi.com/profile/jth1205
This command will provide me with a JSON response of data that I can parse using the “ConvertFrom-JSON” cmdlet in Powershell Version 3. However, I don’t like this format, so I want to get an XML response…something I am a little more familiar with, but just as easily processed by Powershell.
Invoke-WebRequest -URI https://xboxapi.com/xml/profile/jth1205
The section I am interested in is the “Content” field starting on the third line of the response. So, what I will do is capture that information as an XML document into a variable so that I can play around with the data without blowing up the API request limit, which by the way is 250 requests per hour at the time of this writing.
$data = [xml](Invoke-WebRequest -URI https://xboxapi.com/xml/profile/jth1205 | Select-Object -ExpandProperty Content)
All this command does is the same request as before and then get all the information ONLY in the Content field. Using the XML type accelerator, I tell Powershell to treat the data as an XML document and then stuff that XML document object into a variable called $data.
In the screenshot, you can see that when I call the $data variable, I have the standard properties of a XML document. As you can see by drilling down into the properties, I am already getting some usable information about this profile. Notice the API_Limit property that I mentioned before. You can also see the beginnings of the list of games attached to my profile. It is also helpful to see the Success property and verify that it is “1.” Any other response will indicate an error on the request.
I have used my gamertag on this example, but you can use this for any other gamertag that you might know. In the next article, we will look at a couple of other options that you can use in the API and how you might use Powershell to get information from them. Until then, play around with gathering some information on your own Xbox Live profile or that of your friends.