2

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.

Cheesus Toast
  • 1,043
  • 2
  • 15
  • 21

4 Answers4

3

You can use the following nuget Nager.AmazonProductAdvertising package.

PM> Install-Package Nager.AmazonProductAdvertising

Example Controller

public ActionResult ProductSearch(string search)
{
    var authentication = new AmazonAuthentication();
    authentication.AccessKey = "accesskey";
    authentication.SecretKey = "secretkey";

    var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
    var result = wrapper.Search(search);

    return View(result);
}

Example View

@model Nager.AmazonProductAdvertising.Model.AmazonItemResponse
@{
    ViewBag.Title = "Search";
}

<table class="table">
<tr>
    <th>ASIN</th>
    <th>SalesRank</th>
</tr>
@foreach (var item in Model.Items.Item)
{
    <tr>
    <td>@item.ASIN</td>
    <td>@item.SalesRank</td>
    </tr>
}
</table>
live2
  • 3,771
  • 2
  • 37
  • 46
0

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:

  • The current version of the AWS SDK for .NET.
  • All previous major versions of the AWS SDK for .NET.
  • Sample code that demonstrates how to use the AWS SDK for .NET with several AWS services.
Andrii Tsok
  • 1,386
  • 1
  • 13
  • 26
  • You would be surprised at how much research I have done to try to find an official way of using this API with ASP.NET. I think that looks like the kind of thing I was after. I think I may have seen this on nuget - but I was put off by the low amount of Downloads. I find the problem with Amazon is that they have too much documentation and different tools all over the place. – Cheesus Toast Nov 09 '15 at 14:35
  • @CheesusToast They also supporting github repository and as I see they are contributing frequently https://github.com/aws/aws-sdk-net Believe you could find something interesting in their sources. – Andrii Tsok Nov 09 '15 at 14:42
  • @CheesusToast A friend of mine is actually working in Amazon AWS as Software engineer. He also say that they have the MESS in their documentation... a lot of redundant and not useful information. :) – Andrii Tsok Nov 09 '15 at 14:45
  • 1
    The official "Getting Started" guide gave information on how to set up in VS2005. I thought it was a typing mistake - but no... it is really that out of date. – Cheesus Toast Nov 09 '15 at 14:52
  • Actually I am not quite sure this is what I am after. I have altered my question title and content because this is about the advertising API. I am not quite sure why someone down-voted you - I think it was my fault because I should have worded the question making reference to the advertising API. Correct me if I am wrong though. It just seems like this SDK is only related to Amazon's web hosting services as opposed to the advertising API. – Cheesus Toast Nov 09 '15 at 16:07
0

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:

  1. In some instances, large responses require you to modify the MaxReceivedMessageSize and is show on the demo.
  2. I ran into an error with the ImageSets[] in the library. May people have and the fix is here.
Community
  • 1
  • 1
Jeffrey
  • 143
  • 2
  • 10
0

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.

Community
  • 1
  • 1
Cheesus Toast
  • 1,043
  • 2
  • 15
  • 21