Gary Sieling

Retrieve Book Metadata from the Amazon Product API

In order to retrieve information from Amazon, you need to sign up for the “product advertising API”. Make sure to read the license agreement, as it is quite restrictive and long.

Then, to get at it in Node, you can use this handy library:

npm install aws-lib --save

You’ll need to get an access key and ID from the AWS security console. The “associate tag” is your Amazon affiliate ID. Note that you can make as many of these as you want, which is nice for tracking:

const aws = require("aws-lib");

let accessKeyId: String = '...';
let secretAccessKey: String = '...';
let associateTag: String = '...';

const prodAdv = aws.createProdAdvClient(
  accessKeyId, 
  secretAccessKey, 
  associateTag
);

For this example, I’m going to retrieve the metadata for a book, given the URL to it, because this is the data I’m starting from, but you can use the title, or any ID you have for it (ISBN, the Amazon ID, etc).

To get the Amazon ID, we’ll just cut up the URL:

let url = 'http://www.amazon.com/gp/product/0781411181/';
let id = url.split('/product/')[1].split('/')[0];

When you set up the request, you get a fair amount of options1 subject to Amazon highly restricting what they give you. So in this case, I’m requesting their description (EditorialReview), links to the category (current category, parent, child), pricing/availability, title/description, and links to pictures. It’s worth noting that since their database is somewhat large, an item may not be currently available for sale, or may only be available from a merchant, and they expose this to you, as well as whether the item is available through Prime.

const options = {
  IncludeReviewsSummary: false,
  ItemId: id,
  ResponseGroup: 'EditorialReview,BrowseNodes,OfferSummary,ItemAttributes,Images'
};

prodAdv.call(
  "ItemLookup", options, 
  (err, result) => {
    console.log(JSON.stringify(result, null, 2));
  }
);

This will return you a massive JSON payload. You should change the “ResponseGroup” to be the items you want1. Note that you can’t retrieve review information this way, and it looks like they don’t want you to hang onto pricing either.

{
  "@": {
    "xmlns": "http://webservices.amazon.com/AWSECommerceService/2011-08-01"
  },
  "OperationRequest": {
    "RequestId": "e9bc9f67-da3a-4b49-9dd2-2d645c8cad0d",
    "Arguments": {
      "Argument": [
        {
          "@": {
            "Name": "IncludeReviewsSummary",
            "Value": "false"
          }
        },
        {
          "@": {
            "Name": "ItemId",
            "Value": "0781411181"
          }
        },
        {
          "@": {
            "Name": "ResponseGroup",
            "Value": "EditorialReview,BrowseNodes,OfferSummary,ItemAttributes,Im
ages"
          }
        },
        {
          "@": {
            "Name": "Operation",
            "Value": "ItemLookup"
          }
        },
        {
          "@": {
            "Name": "Service",
            "Value": "AWSECommerceService"
          }
        },
        {
          "@": {
            "Name": "Version",
            "Value": "2009-10-01"
          }
        },
        {
          "@": {
            "Name": "Region",
            "Value": "US"
          }
        },
        {
          "@": {
            "Name": "Timestamp",
            "Value": "2016-06-04T13:42:30.104Z"
          }
        }
      ]
    },
    "RequestProcessingTime": "0.0251984530000000"
  },
  "Items": {
    "Request": {
      "IsValid": "True",
      "ItemLookupRequest": {
        "IdType": "ASIN",
        "ItemId": "0781411181",
        "ResponseGroup": [
          "EditorialReview",
          "BrowseNodes",
          "OfferSummary",
          "ItemAttributes",
          "Images"
        ],
        "VariationPage": "All",
        "IncludeReviewsSummary": "false"
      }
    },
    "Item": {
      "ASIN": "0781411181",
      "DetailPageURL": "http://www.amazon.com/Farewell-Mars-Evangelical-Pastors-
Biblical/dp/0781411181%3FSubscriptionId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-s
earch-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D078
1411181",
      "ItemLinks": {
        "ItemLink": [
          {
            "Description": "Technical Details",
            "URL": "http://www.amazon.com/Farewell-Mars-Evangelical-Pastors-Bibl
ical/dp/tech-data/0781411181%3FSubscriptionId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlec
ture-search-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN
%3D0781411181"
          },
          {
            "Description": "Add To Baby Registry",
            "URL": "http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.
0%3D0781411181%26SubscriptionId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-search-20
%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0781411181"

          },
          {
            "Description": "Add To Wedding Registry",
            "URL": "http://www.amazon.com/gp/registry/wedding/add-item.html%3Fas
in.0%3D0781411181%26SubscriptionId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-search
-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D07814111
81"
          },
          {
            "Description": "Add To Wishlist",
            "URL": "http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fa
sin.0%3D0781411181%26SubscriptionId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-searc
h-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3D0781411
181"
          },
          {
            "Description": "Tell A Friend",
            "URL": "http://www.amazon.com/gp/pdp/taf/0781411181%3FSubscriptionId
%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-search-20%26linkCode%3Dxm2%26camp%3D2025
%26creative%3D386001%26creativeASIN%3D0781411181"
          },
          {
            "Description": "All Customer Reviews",
            "URL": "http://www.amazon.com/review/product/0781411181%3FSubscripti
onId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-search-20%26linkCode%3Dxm2%26camp%3D
2025%26creative%3D386001%26creativeASIN%3D0781411181"
          },
          {
            "Description": "All Offers",
            "URL": "http://www.amazon.com/gp/offer-listing/0781411181%3FSubscrip
tionId%3DAKIAIY3QOODXIFFJHLHQ%26tag%3Dlecture-search-20%26linkCode%3Dxm2%26camp%
3D2025%26creative%3D386001%26creativeASIN%3D0781411181"
          }
        ]
      },
      "SmallImage": {
        "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL75_.jpg",

        "Height": {
          "#": "75",
          "@": {
            "Units": "pixels"
          }
        },
        "Width": {
          "#": "50",
          "@": {
            "Units": "pixels"
          }
        }
      },
      "MediumImage": {
        "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL160_.jpg"
,
        "Height": {
          "#": "160",
          "@": {
            "Units": "pixels"
          }
        },
        "Width": {
          "#": "107",
          "@": {
            "Units": "pixels"
          }
        }
      },
      "LargeImage": {
        "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL.jpg",
        "Height": {
          "#": "500",
          "@": {
            "Units": "pixels"
          }
        },
        "Width": {
          "#": "334",
          "@": {
            "Units": "pixels"
          }
        }
      },
      "ImageSets": {
        "ImageSet": {
          "@": {
            "Category": "primary"
          },
          "SwatchImage": {
            "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL30_.j
pg",
            "Height": {
              "#": "30",
              "@": {
                "Units": "pixels"
              }
            },
            "Width": {
              "#": "20",
              "@": {
                "Units": "pixels"
              }
            }
          },
          "SmallImage": {
            "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL75_.j
pg",
            "Height": {
              "#": "75",
              "@": {
                "Units": "pixels"
              }
            },
            "Width": {
              "#": "50",
              "@": {
                "Units": "pixels"
              }
            }
          },
          "ThumbnailImage": {
            "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL75_.j
pg",
            "Height": {
              "#": "75",
              "@": {
                "Units": "pixels"
              }
            },
            "Width": {
              "#": "50",
              "@": {
                "Units": "pixels"
              }
            }
          },
          "TinyImage": {
            "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL110_.
jpg",
            "Height": {
              "#": "110",
              "@": {
                "Units": "pixels"
              }
            },
            "Width": {
              "#": "73",
              "@": {
                "Units": "pixels"
              }
            }
          },
          "MediumImage": {
            "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL._SL160_.
jpg",
            "Height": {
              "#": "160",
              "@": {
                "Units": "pixels"
              }
            },
            "Width": {
              "#": "107",
              "@": {
                "Units": "pixels"
              }
            }
          },
          "LargeImage": {
            "URL": "http://ecx.images-amazon.com/images/I/51yvFfE%2BNPL.jpg",
            "Height": {
              "#": "500",
              "@": {
                "Units": "pixels"
              }
            },
            "Width": {
              "#": "334",
              "@": {
                "Units": "pixels"
              }
            }
          }
        }
      },
      "ItemAttributes": {
        "Author": "Brian Zahnd",
        "Binding": "Paperback",
        "Brand": "David C. Cook",
        "EAN": "9780781411189",
        "EANList": {
          "EANListElement": [
            "0884278786428",
            "9780781411189"
          ]
        },
        "ISBN": "0781411181",
        "ItemDimensions": {
          "Height": {
            "#": "825",
            "@": {
              "Units": "hundredths-inches"
            }
          },
          "Length": {
            "#": "550",
            "@": {
              "Units": "hundredths-inches"
            }
          },
          "Weight": {
            "#": "54",
            "@": {
              "Units": "hundredths-pounds"
            }
          },
          "Width": {
            "#": "70",
            "@": {
              "Units": "hundredths-inches"
            }
          }
        },
        "Label": "David C. Cook",
        "Languages": {
          "Language": [
            {
              "Name": "English",
              "Type": "Published"
            },
            {
              "Name": "English",
              "Type": "Original Language"
            },
            {
              "Name": "English",
              "Type": "Unknown"
            }
          ]
        },
        "ListPrice": {
          "Amount": "1499",
          "CurrencyCode": "USD",
          "FormattedPrice": "$14.99"
        },
        "Manufacturer": "David C. Cook",
        "NumberOfItems": "1",
        "NumberOfPages": "208",
        "PackageDimensions": {
          "Height": {
            "#": "90",
            "@": {
              "Units": "hundredths-inches"
            }
          },
          "Length": {
            "#": "820",
            "@": {
              "Units": "hundredths-inches"
            }
          },
          "Weight": {
            "#": "50",
            "@": {
              "Units": "hundredths-pounds"
            }
          },
          "Width": {
            "#": "560",
            "@": {
              "Units": "hundredths-inches"
            }
          }
        },
        "PackageQuantity": "1",
        "ProductGroup": "Book",
        "ProductTypeName": "ABIS_BOOK",
        "PublicationDate": "2014-06-01",
        "Publisher": "David C. Cook",
        "ReleaseDate": "2014-06-01",
        "Studio": "David C. Cook",
        "Title": "A Farewell to Mars: An Evangelical Pastor's Journey Toward the
 Biblical Gospel of Peace",
        "UPC": "884278786428",
        "UPCList": {
          "UPCListElement": "884278786428"
        }
      },
      "OfferSummary": {
        "LowestNewPrice": {
          "Amount": "223",
          "CurrencyCode": "USD",
          "FormattedPrice": "$2.23"
        },
        "LowestUsedPrice": {
          "Amount": "490",
          "CurrencyCode": "USD",
          "FormattedPrice": "$4.90"
        },
        "TotalNew": "35",
        "TotalUsed": "25",
        "TotalCollectible": "0",
        "TotalRefurbished": "0"
      },
      "EditorialReviews": {
        "EditorialReview": {
          "Source": "Product Description",
          "Content": "
We know Jesus the Savior, but have we met Jesus, Prin ce of Peace?
 
When did we accept vengeance as an acceptable part of the Christian life? How did violence and power seep into our understand ing of faith and grace? For those troubled by this trend toward the sword, perha ps there is a better way.
 
What if the message of Jesus dif fers radically from the drumbeats of war we hear all around us?
 
Using his own journey from war crier to peacemaker and his in-depth study of peace in the scriptures, author and pastor Brian Zahnd reintroduces us to the gospel of Peace.
", "IsLinkSuppressed": "0" } }, "BrowseNodes": { "BrowseNode": [ { "BrowseNodeId": "12333", "Name": "Christian Living", "Children": { "BrowseNode": [ { "BrowseNodeId": "297488", "Name": "Business & Professional Growth" }, { "BrowseNodeId": "12376", "Name": "Counseling" }, { "BrowseNodeId": "69721", "Name": "Dating & Relationships" }, { "BrowseNodeId": "7259412011", "Name": "Death & Grief" }, { "BrowseNodeId": "7259413011", "Name": "Devotionals" }, { "BrowseNodeId": "12339", "Name": "Faith" }, { "BrowseNodeId": "7259415011", "Name": "Family" }, { "BrowseNodeId": "12391", "Name": "Holidays" }, { "BrowseNodeId": "12343", "Name": "Leadership" }, { "BrowseNodeId": "69722", "Name": "Marriage" }, { "BrowseNodeId": "7259417011", "Name": "Men's Issues" }, { "BrowseNodeId": "15755421", "Name": "Music" }, { "BrowseNodeId": "7288680011", "Name": "Self Help" }, { "BrowseNodeId": "7259419011", "Name": "Personal Growth" }, { "BrowseNodeId": "7259420011", "Name": "Social Issues" }, { "BrowseNodeId": "7259421011", "Name": "Spiritual Growth" }, { "BrowseNodeId": "7259422011", "Name": "Spiritual Warfare" }, { "BrowseNodeId": "12345", "Name": "Stewardship" }, { "BrowseNodeId": "3043241", "Name": "Women's Issues" } ] }, "Ancestors": { "BrowseNode": { "BrowseNodeId": "12290", "Name": "Christian Books & Bibles", "Ancestors": { "BrowseNode": { "BrowseNodeId": "1000", "Name": "Subjects", "IsCategoryRoot": "1", "Ancestors": { "BrowseNode": { "BrowseNodeId": "283155", "Name": "Books" } } } } } } }, { "BrowseNodeId": "22", "Name": "Religion & Spirituality", "Children": { "BrowseNode": [ { "BrowseNodeId": "12762", "Name": "Agnosticism" }, { "BrowseNodeId": "12764", "Name": "Atheism" }, { "BrowseNodeId": "12279", "Name": "Buddhism" }, { "BrowseNodeId": "12290", "Name": "Christian Books & Bibles" }, { "BrowseNodeId": "12506", "Name": "Hinduism" }, { "BrowseNodeId": "12522", "Name": "Islam" }, { "BrowseNodeId": "12540", "Name": "Judaism" }, { "BrowseNodeId": "12489", "Name": "Literature & Fiction" }, { "BrowseNodeId": "12621", "Name": "New Age & Spirituality" }, { "BrowseNodeId": "12689", "Name": "Occult & Paranormal" }, { "BrowseNodeId": "12735", "Name": "Other Eastern Religions & Sacred Texts" }, { "BrowseNodeId": "12761", "Name": "Other Religions, Practices & Sacred Texts" }, { "BrowseNodeId": "1873", "Name": "Religious Art" }, { "BrowseNodeId": "12779", "Name": "Religious Studies" }, { "BrowseNodeId": "12809", "Name": "Worship & Devotion" } ] }, "Ancestors": { "BrowseNode": { "BrowseNodeId": "1000", "Name": "Subjects", "IsCategoryRoot": "1", "Ancestors": { "BrowseNode": { "BrowseNodeId": "283155", "Name": "Books" } } } } } ] } } } }
  1. http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html [] []
Exit mobile version