I have finally got the Amazon product advertising API to work on my MVC 5 site. I am using the "SignedRequestHelper" class that was provided on one of the downloads from the Amazon site. I have actually got a ref to the Amazon API but I do not seem to be using it at all at present.
What I am using so far is (controller):
SignedRequestHelper helper = new SignedRequestHelper("myAWSaccessKeyID",
"mysecretKey", "webservices.amazon.co.uk");
Dictionary<String, String> items = new Dictionary<String, String>();
items.Add("Service", "AWSECommerceService");
items.Add("Operation", "ItemSearch");
items.Add("AWSAccessKeyId", "myAWSaccessKeyID");
items.Add("AssociateTag", "myTag");
items.Add("SearchIndex", SearchIndex);//This is a string value (selectbox)
items.Add("ResponseGroup", "Images,ItemAttributes,OfferFull,Offers,OfferSummary,Reviews");
items.Add("Keywords", keyword);//This is a string value
string requestUrl = helper.Sign(items);
ViewBag.Stuff = requestUrl;//Just so I could see the whole URL!
WebRequest request = HttpWebRequest.Create(requestUrl);
WebResponse response = request.GetResponse();
XmlDocument doc = new XmlDocument();
doc.Load(response.GetResponseStream());
XmlNodeList titleNodes = doc.GetElementsByTagName("Item");
ViewBag.Titles = titleNodes;
You may notice I partially the copied the style of JAVA code from the scratch pad.
From that point on in the view I just deal with each part as it comes. It is kind of messy and horrid and dealing with switches like this:
foreach (System.Xml.XmlNode item in ViewBag.Titles)
{
<h3>Item: @count</h3>
foreach (System.Xml.XmlNode child in item.ChildNodes)
{
switch (child.Name)
{
case "ASIN":
<p>ASIN: @child.InnerText</p>
break;
case "MediumImage":
<img src="@child.ChildNodes[0].InnerText" />
break;
case "ItemAttributes":
foreach (System.Xml.XmlNode child1 in child.ChildNodes)
{
if(child1.Name == "Title")
{
<p>@child1.InnerText</p>
}
}
break;
}
}
count++;
}
It works and I can use the XML document etc. I just need to know if there is a way to change it so that it is actually using the API part that was given as a reference. I would rather use proper tools than do it with raw XML like this. I had such difficulty connecting with the Amazon documentation that I basically just tried to connect in the JAVA style code on Amazon's scratchpad.
I believe that I have finally found a way to use the actual Amazon Prod Adv API now. The problem was working out how to sign the request using the latest API (that I had added as a reference). The reference was added in a similar way to the getting started guide even though that was making reference to VS2005. That is obviously 10 years old but I somehow did get it working with a bit of problem solving. I just never got the signing correct so I ended up using that horrid REST bodge (in my original question)!
The post that has helped me now is this one: amazon product advertising api - item lookup request working example
It is the one marked as the answer. It has only 4 up-votes but it is the best thing I have found. I put all the classes into the controller to test it but I will now have to do it properly using models or extension classes. It worked anyway though.
Take a look to AWS SDK for .Net. Also you can find some guides and how to work with it's APIs.
The AWS SDK for .NET includes the following:
There is a library that is incredibly thorough for dealing with the Amazon Product Advertising API (PAAPI). When you make a request, you can receive a variety of responses, but this library can handle them all! It reads the XML and puts all the information in an object.
I'm working on two MVC 5 sites right now that interact with the PAAPI. I have a separate folder with the files and a couple files I wrote to make requests and process responses by pulling the data I need out of the object created by the library.
I made a C# console app demo, and you can view it here:
https://github.com/zoenberger/AmazonProductAdvertising
I used this for guidance: https://flyingpies.wordpress.com/2009/08/01/17/
However, I ran into a couple errors:
You can use the following nuget Nager.AmazonProductAdvertising package.
Example Controller
Example View