powershellapiwebrequestisbnamazon-advertising-api

Use Powershell to get book metadata from Amazon


I want to use the Amazon Product Advertising API to create a Web Request with Powershell which submits the ISBN / ANSI number and returns the Book Metadata. (Title, Author,...)

So far I have createt a Account to geht the AssociateTag, AWSAccessKeyId and AWS Secret Key. With this Information I am able to create a signed WebRequest on the Test Page, which works perfect. http://associates-amazon.s3.amazonaws.com/scratchpad/index.html

Now my question is, how to create this WebRequest with Powershell and sign the "String-to-Sign" with my Sec Key?

The Documentation http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/rest-signature.html shows, that the we need to generate a HMAC-SHA256 Hash key wich will be add to the WebRequest. But I were not able to create such a hash...

**
$AwsSecKey = "1234567890"

$string = "GET
webservices.amazon.com
/onca/xml
AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&ItemId=0679722769&Operation=I
temLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReview
s&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&
Version=2009-01-06"

$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($key)
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($string))
$sig = [string]::join("", ($signature | % {([int]$_).toString('x2')}))
**

Hope somebody could help me out with this...

Thanks, Andreas


Solution

  • The library pointed to by Zach is probably your best bet. But you are on the right track, I think the only piece you have wrong is that to construct the final hash string, you need to do

    $sig = [Convert]::ToBase64String($signature)