📜 ⬆️ ⬇️

Using Amazon's Product Advertising API

Good day, habrovchane!

image

In this post I want to talk about my first experience with the Amazon Product Advertising API . This API allows you to perform a parameterized search for products and all information associated with them on Amazon sites. There is also an affiliate program for help, which can be monetized in the future (1. Get Affiliate ID, 2. Add it to requests, 3. Profit? ...). You can register affiliate program here .
If interested, read on.
')

Prehistory


I will start the post with a prehistory, why do I go there? It was 2012, March, the very beginning. And on the horizon, “International Women's Day” began to be seen, in which it is customary to give flowers, various kinds of gifts, to their mothers, wives, daughters, girls. After a few minutes of reflection, it was decided to buy the second iPad and flowers for the wife, respectively. Since flowers, unlike a device, can be purchased without problems, it was decided to postpone their purchase on that very day “X”. In the city in which I live, the market of all kinds of gadgets is poorly developed, there is no healthy competition (and, in principle, unhealthy too), so the prices are simply exorbitant. By luck, my colleague was on a business trip overseas and I decided to buy a device on Amazon.com . There were lots of offers, prices also ranged from $ 300 to $ 700. And once, I went to the site in search of a better deal and saw that some reseller had thrown 8 new devices for sale at a ridiculous price, while I was trying to checkout and fill in the form, they had already been smoked. A little googling on this topic, it was decided to write something to monitor prices for this device.

Inception


To begin with, go to your AWS account , go to Security Credentials and click on Create a new Access Key . As a result, get the following picture:

A cherished pair of keys received, let's test it . We enter our keys on the form, in the Unsigned URL we write for our specific situation URL:
http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService &Version=2011-08-01 &AssociateTag=520 &Operation=ItemLookup &ResponseGroup=Large &ItemId=B0047DVWLW 


I will explain a little, I did not register affiliate program therefore AssociateTag from the head. Operation = ItemLookup (all operations that the service supports can be viewed here ) returns all or some of the properties (depending on the ResponseGroup ) on the desired ItemId (which can be determined by the URL ).

Click the Display Signed URL ... and voila, we have a link signed by our keys! Going through it we get:

XML Response of the form (it was necessary to short a bit, Habr refused to eat it entirely):
 <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <HTTPHeaders> <Header Name="UserAgent" Value="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1"/> </HTTPHeaders> <RequestId>9645cf90-c1ae-4505-be21-08198e5e8274</RequestId> <Arguments> <Argument Name="ItemId" Value="B0047DVWLW"/> <Argument Name="Operation" Value="ItemLookup"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="AWSAccessKeyId" Value="AKIAILZWKKRUXK7QRNRA"/> <Argument Name="Timestamp" Value="2012-09-21T10:34:09.000Z"/> <Argument Name="Signature" Value="w8kK7v5WuPO2lxaUwtnw1fax10SMcqN8Wg8qTqUDeHQ="/> <Argument Name="ResponseGroup" Value="Large"/> <Argument Name="AssociateTag" Value="520"/> <Argument Name="Version" Value="2011-08-01"/> </Arguments> <RequestProcessingTime>0.2015160000000000</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>True</IsValid> <ItemLookupRequest> <IdType>ASIN</IdType> <ItemId>B0047DVWLW</ItemId> <ResponseGroup>Large</ResponseGroup> <VariationPage>All</VariationPage> </ItemLookupRequest> </Request> <Item> <ASIN>B0047DVWLW</ASIN> <ParentASIN>B004QGY7M6</ParentASIN> <DetailPageURL> http://www.amazon.com/Apple-MC979LL-Tablet-White-Generation/dp/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0047DVWLW </DetailPageURL> <ItemLinks> <ItemLink> <Description>Technical Details</Description> <URL> http://www.amazon.com/Apple-MC979LL-Tablet-White-Generation/dp/tech-data/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Add To Baby Registry</Description> <URL> http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3DB0047DVWLW%26SubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Add To Wedding Registry</Description> <URL> http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3DB0047DVWLW%26SubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Add To Wishlist</Description> <URL> http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3DB0047DVWLW%26SubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Tell A Friend</Description> <URL> http://www.amazon.com/gp/pdp/taf/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>All Customer Reviews</Description> <URL> http://www.amazon.com/review/product/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>All Offers</Description> <URL> http://www.amazon.com/gp/offer-listing/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> </ItemLinks> <SalesRank>8</SalesRank> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL75_.jpg </URL> <Height Units="pixels">63</Height> <Width Units="pixels">75</Width> </SmallImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL160_.jpg </URL> <Height Units="pixels">135</Height> <Width Units="pixels">160</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL.jpg </URL> <Height Units="pixels">365</Height> <Width Units="pixels">434</Width> </LargeImage> <ImageSets> <ImageSet Category="primary"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL30_.jpg </URL> <Height Units="pixels">25</Height> <Width Units="pixels">30</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL75_.jpg </URL> <Height Units="pixels">63</Height> <Width Units="pixels">75</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL75_.jpg </URL> <Height Units="pixels">63</Height> <Width Units="pixels">75</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL110_.jpg </URL> <Height Units="pixels">93</Height> <Width Units="pixels">110</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL160_.jpg </URL> <Height Units="pixels">135</Height> <Width Units="pixels">160</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL.jpg </URL> <Height Units="pixels">365</Height> <Width Units="pixels">434</Width> </LargeImage> </ImageSet> <ImageSet Category="variant"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL30_.jpg </URL> <Height Units="pixels">15</Height> <Width Units="pixels">30</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL75_.jpg </URL> <Height Units="pixels">38</Height> <Width Units="pixels">75</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL75_.jpg </URL> <Height Units="pixels">38</Height> <Width Units="pixels">75</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL110_.jpg </URL> <Height Units="pixels">56</Height> <Width Units="pixels">110</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL160_.jpg </URL> <Height Units="pixels">81</Height> <Width Units="pixels">160</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L.jpg </URL> <Height Units="pixels">253</Height> <Width Units="pixels">500</Width> </LargeImage> </ImageSet> <ImageSet Category="variant"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL30_.jpg </URL> <Height Units="pixels">30</Height> <Width Units="pixels">25</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">61</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">61</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL110_.jpg </URL> <Height Units="pixels">110</Height> <Width Units="pixels">90</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL160_.jpg </URL> <Height Units="pixels">160</Height> <Width Units="pixels">131</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L.jpg </URL> <Height Units="pixels">500</Height> <Width Units="pixels">409</Width> </LargeImage> </ImageSet> <ImageSet Category="variant"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL30_.jpg </URL> <Height Units="pixels">30</Height> <Width Units="pixels">25</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">63</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">63</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL110_.jpg </URL> <Height Units="pixels">110</Height> <Width Units="pixels">93</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL160_.jpg </URL> <Height Units="pixels">160</Height> <Width Units="pixels">135</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL.jpg </URL> <Height Units="pixels">365</Height> <Width Units="pixels">309</Width> </LargeImage> </ImageSet> </ImageSets> <ItemAttributes> <Binding>Personal Computers</Binding> <Brand>Apple</Brand> <CatalogNumberList> <CatalogNumberListElement>B0047DVWLW</CatalogNumberListElement> </CatalogNumberList> <Color>White</Color> <EAN>0885909471812</EAN> <EANList> <EANListElement>0885909471812</EANListElement> <EANListElement>0811331000009</EANListElement> </EANList> <Feature>Designed for Apple's 2nd generation of iPads</Feature> <Feature> 9.7-inch (diagonal) LED-backlit glossy widescreen Multi-Touch display with IPS technology </Feature> <Feature>1 GHz dual-core Apple A5 custom-designed processor</Feature> <Feature>Forward facing and rear facing cameras</Feature> <Feature>Apple's iOS 4 and access to Apple's app store</Feature> <Format>CD-ROM</Format> <HardwarePlatform>Mac</HardwarePlatform> <IsAutographed>0</IsAutographed> <IsEligibleForTradeIn>1</IsEligibleForTradeIn> <IsMemorabilia>0</IsMemorabilia> <ItemDimensions> <Height Units="hundredths-inches">949</Height> <Length Units="hundredths-inches">35</Length> <Weight Units="hundredths-pounds">133</Weight> <Width Units="hundredths-inches">732</Width> </ItemDimensions> <Label>Apple Computer</Label> <LegalDisclaimer> Item Will Not Be Shipped Until Payment Clears And Funds Are Tranferred To My Bank Account! </LegalDisclaimer> <ListPrice> <Amount>39900</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$399.00</FormattedPrice> </ListPrice> <Manufacturer>Apple Computer</Manufacturer> <Model>MC979LL/A</Model> <MPN>MC979LL/A</MPN> <NumberOfItems>1</NumberOfItems> <OperatingSystem>Apple iOS 5.0</OperatingSystem> <PackageDimensions> <Height Units="hundredths-inches">350</Height> <Length Units="hundredths-inches">1140</Length> <Weight Units="hundredths-pounds">133</Weight> <Width Units="hundredths-inches">960</Width> </PackageDimensions> <PackageQuantity>1</PackageQuantity> <PartNumber>MC979LL/A</PartNumber> <ProductGroup>Personal Computer</ProductGroup> <ProductTypeName>TABLET_COMPUTER</ProductTypeName> <Publisher>Apple Computer</Publisher> <Size>16GB</Size> <SKU>118087@634532900684301250</SKU> <Studio>Apple Computer</Studio> <Title> Apple iPad 2 MC979LL/A Tablet (16GB, Wifi, White) 2nd Generation </Title> <TradeInValue> <Amount>33000</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$330.00</FormattedPrice> </TradeInValue> <UPC>811331000009</UPC> <UPCList> <UPCListElement>811331000009</UPCListElement> <UPCListElement>885909471812</UPCListElement> </UPCList> </ItemAttributes> <OfferSummary> <LowestNewPrice> <Amount>39900</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$399.00</FormattedPrice> </LowestNewPrice> <LowestUsedPrice> <Amount>34000</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$340.00</FormattedPrice> </LowestUsedPrice> <LowestRefurbishedPrice> <Amount>34999</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$349.99</FormattedPrice> </LowestRefurbishedPrice> <TotalNew>85</TotalNew> <TotalUsed>100</TotalUsed> <TotalCollectible>0</TotalCollectible> <TotalRefurbished>17</TotalRefurbished> </OfferSummary> <Offers> <TotalOffers>1</TotalOffers> <TotalOfferPages>1</TotalOfferPages> <MoreOffersUrl> http://www.amazon.com/gp/offer-listing/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </MoreOffersUrl> <Offer> <OfferAttributes> <Condition>New</Condition> </OfferAttributes> <OfferListing> <OfferListingId> 5tIFOSgtOfWUjj1N2%2FBqWUyXOtsYzDcDWOygGn8T3wdoo5gs1FLVQGbaoTAnVlGmTXh1rWsYI57d%2FfNHr%2BWexLUNQrcrhi1RM1OxR%2B65I%2Fs2Ofz0nfJ83bhbwZNUqm75udmgNjgk2t%2F3%2FJhFd5Cc87KIbmpEK7SH </OfferListingId> <Price> <Amount>41400</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$414.00</FormattedPrice> </Price> <AvailabilityAttributes> <AvailabilityType>futureDate</AvailabilityType> <MinimumHours>0</MinimumHours> <MaximumHours>0</MaximumHours> </AvailabilityAttributes> <IsEligibleForSuperSaverShipping>1</IsEligibleForSuperSaverShipping> </OfferListing> </Offer> </Offers> 2B65I% 2Fs2Ofz0nfJ83bhbwZNUqm75udmgNjgk2t% 2F3% 2FJhFd5Cc87KIbmpEK7SH <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <HTTPHeaders> <Header Name="UserAgent" Value="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1"/> </HTTPHeaders> <RequestId>9645cf90-c1ae-4505-be21-08198e5e8274</RequestId> <Arguments> <Argument Name="ItemId" Value="B0047DVWLW"/> <Argument Name="Operation" Value="ItemLookup"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="AWSAccessKeyId" Value="AKIAILZWKKRUXK7QRNRA"/> <Argument Name="Timestamp" Value="2012-09-21T10:34:09.000Z"/> <Argument Name="Signature" Value="w8kK7v5WuPO2lxaUwtnw1fax10SMcqN8Wg8qTqUDeHQ="/> <Argument Name="ResponseGroup" Value="Large"/> <Argument Name="AssociateTag" Value="520"/> <Argument Name="Version" Value="2011-08-01"/> </Arguments> <RequestProcessingTime>0.2015160000000000</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>True</IsValid> <ItemLookupRequest> <IdType>ASIN</IdType> <ItemId>B0047DVWLW</ItemId> <ResponseGroup>Large</ResponseGroup> <VariationPage>All</VariationPage> </ItemLookupRequest> </Request> <Item> <ASIN>B0047DVWLW</ASIN> <ParentASIN>B004QGY7M6</ParentASIN> <DetailPageURL> http://www.amazon.com/Apple-MC979LL-Tablet-White-Generation/dp/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0047DVWLW </DetailPageURL> <ItemLinks> <ItemLink> <Description>Technical Details</Description> <URL> http://www.amazon.com/Apple-MC979LL-Tablet-White-Generation/dp/tech-data/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Add To Baby Registry</Description> <URL> http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3DB0047DVWLW%26SubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Add To Wedding Registry</Description> <URL> http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3DB0047DVWLW%26SubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Add To Wishlist</Description> <URL> http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3DB0047DVWLW%26SubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>Tell A Friend</Description> <URL> http://www.amazon.com/gp/pdp/taf/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>All Customer Reviews</Description> <URL> http://www.amazon.com/review/product/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> <ItemLink> <Description>All Offers</Description> <URL> http://www.amazon.com/gp/offer-listing/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </URL> </ItemLink> </ItemLinks> <SalesRank>8</SalesRank> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL75_.jpg </URL> <Height Units="pixels">63</Height> <Width Units="pixels">75</Width> </SmallImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL160_.jpg </URL> <Height Units="pixels">135</Height> <Width Units="pixels">160</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL.jpg </URL> <Height Units="pixels">365</Height> <Width Units="pixels">434</Width> </LargeImage> <ImageSets> <ImageSet Category="primary"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL30_.jpg </URL> <Height Units="pixels">25</Height> <Width Units="pixels">30</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL75_.jpg </URL> <Height Units="pixels">63</Height> <Width Units="pixels">75</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL75_.jpg </URL> <Height Units="pixels">63</Height> <Width Units="pixels">75</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL110_.jpg </URL> <Height Units="pixels">93</Height> <Width Units="pixels">110</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL._SL160_.jpg </URL> <Height Units="pixels">135</Height> <Width Units="pixels">160</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/41Yisrlx%2BFL.jpg </URL> <Height Units="pixels">365</Height> <Width Units="pixels">434</Width> </LargeImage> </ImageSet> <ImageSet Category="variant"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL30_.jpg </URL> <Height Units="pixels">15</Height> <Width Units="pixels">30</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL75_.jpg </URL> <Height Units="pixels">38</Height> <Width Units="pixels">75</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL75_.jpg </URL> <Height Units="pixels">38</Height> <Width Units="pixels">75</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL110_.jpg </URL> <Height Units="pixels">56</Height> <Width Units="pixels">110</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L._SL160_.jpg </URL> <Height Units="pixels">81</Height> <Width Units="pixels">160</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/31lmfWbe6-L.jpg </URL> <Height Units="pixels">253</Height> <Width Units="pixels">500</Width> </LargeImage> </ImageSet> <ImageSet Category="variant"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL30_.jpg </URL> <Height Units="pixels">30</Height> <Width Units="pixels">25</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">61</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">61</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL110_.jpg </URL> <Height Units="pixels">110</Height> <Width Units="pixels">90</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L._SL160_.jpg </URL> <Height Units="pixels">160</Height> <Width Units="pixels">131</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/41omkn%2BPH6L.jpg </URL> <Height Units="pixels">500</Height> <Width Units="pixels">409</Width> </LargeImage> </ImageSet> <ImageSet Category="variant"> <SwatchImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL30_.jpg </URL> <Height Units="pixels">30</Height> <Width Units="pixels">25</Width> </SwatchImage> <SmallImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">63</Width> </SmallImage> <ThumbnailImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL75_.jpg </URL> <Height Units="pixels">75</Height> <Width Units="pixels">63</Width> </ThumbnailImage> <TinyImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL110_.jpg </URL> <Height Units="pixels">110</Height> <Width Units="pixels">93</Width> </TinyImage> <MediumImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL._SL160_.jpg </URL> <Height Units="pixels">160</Height> <Width Units="pixels">135</Width> </MediumImage> <LargeImage> <URL> http://ecx.images-amazon.com/images/I/31gqTQEEqAL.jpg </URL> <Height Units="pixels">365</Height> <Width Units="pixels">309</Width> </LargeImage> </ImageSet> </ImageSets> <ItemAttributes> <Binding>Personal Computers</Binding> <Brand>Apple</Brand> <CatalogNumberList> <CatalogNumberListElement>B0047DVWLW</CatalogNumberListElement> </CatalogNumberList> <Color>White</Color> <EAN>0885909471812</EAN> <EANList> <EANListElement>0885909471812</EANListElement> <EANListElement>0811331000009</EANListElement> </EANList> <Feature>Designed for Apple's 2nd generation of iPads</Feature> <Feature> 9.7-inch (diagonal) LED-backlit glossy widescreen Multi-Touch display with IPS technology </Feature> <Feature>1 GHz dual-core Apple A5 custom-designed processor</Feature> <Feature>Forward facing and rear facing cameras</Feature> <Feature>Apple's iOS 4 and access to Apple's app store</Feature> <Format>CD-ROM</Format> <HardwarePlatform>Mac</HardwarePlatform> <IsAutographed>0</IsAutographed> <IsEligibleForTradeIn>1</IsEligibleForTradeIn> <IsMemorabilia>0</IsMemorabilia> <ItemDimensions> <Height Units="hundredths-inches">949</Height> <Length Units="hundredths-inches">35</Length> <Weight Units="hundredths-pounds">133</Weight> <Width Units="hundredths-inches">732</Width> </ItemDimensions> <Label>Apple Computer</Label> <LegalDisclaimer> Item Will Not Be Shipped Until Payment Clears And Funds Are Tranferred To My Bank Account! </LegalDisclaimer> <ListPrice> <Amount>39900</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$399.00</FormattedPrice> </ListPrice> <Manufacturer>Apple Computer</Manufacturer> <Model>MC979LL/A</Model> <MPN>MC979LL/A</MPN> <NumberOfItems>1</NumberOfItems> <OperatingSystem>Apple iOS 5.0</OperatingSystem> <PackageDimensions> <Height Units="hundredths-inches">350</Height> <Length Units="hundredths-inches">1140</Length> <Weight Units="hundredths-pounds">133</Weight> <Width Units="hundredths-inches">960</Width> </PackageDimensions> <PackageQuantity>1</PackageQuantity> <PartNumber>MC979LL/A</PartNumber> <ProductGroup>Personal Computer</ProductGroup> <ProductTypeName>TABLET_COMPUTER</ProductTypeName> <Publisher>Apple Computer</Publisher> <Size>16GB</Size> <SKU>118087@634532900684301250</SKU> <Studio>Apple Computer</Studio> <Title> Apple iPad 2 MC979LL/A Tablet (16GB, Wifi, White) 2nd Generation </Title> <TradeInValue> <Amount>33000</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$330.00</FormattedPrice> </TradeInValue> <UPC>811331000009</UPC> <UPCList> <UPCListElement>811331000009</UPCListElement> <UPCListElement>885909471812</UPCListElement> </UPCList> </ItemAttributes> <OfferSummary> <LowestNewPrice> <Amount>39900</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$399.00</FormattedPrice> </LowestNewPrice> <LowestUsedPrice> <Amount>34000</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$340.00</FormattedPrice> </LowestUsedPrice> <LowestRefurbishedPrice> <Amount>34999</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$349.99</FormattedPrice> </LowestRefurbishedPrice> <TotalNew>85</TotalNew> <TotalUsed>100</TotalUsed> <TotalCollectible>0</TotalCollectible> <TotalRefurbished>17</TotalRefurbished> </OfferSummary> <Offers> <TotalOffers>1</TotalOffers> <TotalOfferPages>1</TotalOfferPages> <MoreOffersUrl> http://www.amazon.com/gp/offer-listing/B0047DVWLW%3FSubscriptionId%3DAKIAILZWKKRUXK7QRNRA%26tag%3D520%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB0047DVWLW </MoreOffersUrl> <Offer> <OfferAttributes> <Condition>New</Condition> </OfferAttributes> <OfferListing> <OfferListingId> 5tIFOSgtOfWUjj1N2%2FBqWUyXOtsYzDcDWOygGn8T3wdoo5gs1FLVQGbaoTAnVlGmTXh1rWsYI57d%2FfNHr%2BWexLUNQrcrhi1RM1OxR%2B65I%2Fs2Ofz0nfJ83bhbwZNUqm75udmgNjgk2t%2F3%2FJhFd5Cc87KIbmpEK7SH </OfferListingId> <Price> <Amount>41400</Amount> <CurrencyCode>USD</CurrencyCode> <FormattedPrice>$414.00</FormattedPrice> </Price> <AvailabilityAttributes> <AvailabilityType>futureDate</AvailabilityType> <MinimumHours>0</MinimumHours> <MaximumHours>0</MaximumHours> </AvailabilityAttributes> <IsEligibleForSuperSaverShipping>1</IsEligibleForSuperSaverShipping> </OfferListing> </Offer> </Offers> 



From the Response, you can see what information gives us value (for example, ResponseGroup = Large was taken, so we received a lot of redundant data for a specific problem, ResponseGroup = Offers would be better).

All information on working with the service can be found in the Developers Guide .

Bicycle search


Service provides WSDL . Those. if we add it as a Web Service Reference to our solution, in the end, we get a proxy to work with the service. Everything would be fine, but the Request which we will send to the service should also be signed with the received SAK (Secret Access Key).
The authentication process with ours is as follows:

AWS side:

Everything is very clear, but the service lacks functionality for your SAK rickstand subscription. The simplest solution at the time seemed to look at the samples and find the functionality we need, but not everything is as simple as it seems. Of all the samples revised by me, it was not possible to find a working code for signing the quest. Quickly googling there was a solution:
C # Request Signing Solution
 class SignRequestHelper { private string endPoint; private string akid; private byte[] secret; private HMAC signer; private const string REQUEST_URI = "/onca/xml"; private const string REQUEST_METHOD = "GET"; /* * Use this constructor to create the object. The AWS credentials are available on * http://aws.amazon.com * * The destination is the service end-point for your application: * US: ecs.amazonaws.com * JP: ecs.amazonaws.jp * UK: ecs.amazonaws.co.uk * DE: ecs.amazonaws.de * FR: ecs.amazonaws.fr * CA: ecs.amazonaws.ca */ public SignRequestHelper(string awsAccessKeyId, string awsSecretKey, string destination) { this.endPoint = destination.ToLower(); this.akid = awsAccessKeyId; this.secret = Encoding.UTF8.GetBytes(awsSecretKey); this.signer = new HMACSHA256(this.secret); } /* * Sign a request in the form of a Dictionary of name-value pairs. * * This method returns a complete URL to use. Modifying the returned URL * in any way invalidates the signature and Amazon will reject the requests. */ public string Sign(IDictionary<string, string> request) { // Use a SortedDictionary to get the parameters in natural byte order, as // required by AWS. ParamComparer pc = new ParamComparer(); SortedDictionary<string, string> sortedMap = new SortedDictionary<string, string>(request, pc); // Add the AWSAccessKeyId and Timestamp to the requests. sortedMap["AWSAccessKeyId"] = this.akid; sortedMap["Timestamp"] = this.GetTimestamp(); // Get the canonical query string string canonicalQS = this.ConstructCanonicalQueryString(sortedMap); // Derive the bytes needs to be signed. StringBuilder builder = new StringBuilder(); builder.Append(REQUEST_METHOD) .Append("\n") .Append(this.endPoint) .Append("\n") .Append(REQUEST_URI) .Append("\n") .Append(canonicalQS); string stringToSign = builder.ToString(); byte[] toSign = Encoding.UTF8.GetBytes(stringToSign); // Compute the signature and convert to Base64. byte[] sigBytes = signer.ComputeHash(toSign); string signature = Convert.ToBase64String(sigBytes); // now construct the complete URL and return to caller. StringBuilder qsBuilder = new StringBuilder(); qsBuilder.Append("http://") .Append(this.endPoint) .Append(REQUEST_URI) .Append("?") .Append(canonicalQS) .Append("&Signature=") .Append(this.PercentEncodeRfc3986(signature)); return qsBuilder.ToString(); } /* * Sign a request in the form of a query string. * * This method returns a complete URL to use. Modifying the returned URL * in any way invalidates the signature and Amazon will reject the requests. */ public string Sign(string queryString) { IDictionary<string, string> request = this.CreateDictionary(queryString); return this.Sign(request); } /* * Current time in IS0 8601 format as required by Amazon */ private string GetTimestamp() { DateTime currentTime = DateTime.UtcNow; string timestamp = currentTime.ToString("yyyy-MM-ddTHH:mm:ssZ"); return timestamp; } /* * Percent-encode (URL Encode) according to RFC 3986 as required by Amazon. * * This is necessary because .NET's HttpUtility.UrlEncode does not encode * according to the above standard. Also, .NET returns lower-case encoding * by default and Amazon requires upper-case encoding. */ private string PercentEncodeRfc3986(string str) { str = HttpUtility.UrlEncode(str, System.Text.Encoding.UTF8); str = str.Replace("'", "%27").Replace("(", "%28").Replace(")", "%29").Replace("*", "%2A").Replace("!", "%21").Replace("%7e", "~").Replace("+", "%20"); StringBuilder sbuilder = new StringBuilder(str); for (int i = 0; i < sbuilder.Length; i++) { if (sbuilder[i] == '%') { if (Char.IsLetter(sbuilder[i + 1]) || Char.IsLetter(sbuilder[i + 2])) { sbuilder[i + 1] = Char.ToUpper(sbuilder[i + 1]); sbuilder[i + 2] = Char.ToUpper(sbuilder[i + 2]); } } } return sbuilder.ToString(); } /* * Convert a query string to corresponding dictionary of name-value pairs. */ private IDictionary<string, string> CreateDictionary(string queryString) { Dictionary<string, string> map = new Dictionary<string, string>(); string[] requestParams = queryString.Split('&'); for (int i = 0; i < requestParams.Length; i++) { if (requestParams[i].Length < 1) { continue; } char[] sep = { '=' }; string[] param = requestParams[i].Split(sep, 2); for (int j = 0; j < param.Length; j++) { param[j] = HttpUtility.UrlDecode(param[j], System.Text.Encoding.UTF8); } switch (param.Length) { case 1: { if (requestParams[i].Length >= 1) { if (requestParams[i].ToCharArray()[0] == '=') { map[""] = param[0]; } else { map[param[0]] = ""; } } break; } case 2: { if (!string.IsNullOrEmpty(param[0])) { map[param[0]] = param[1]; } } break; } } return map; } private string ConstructCanonicalQueryString(SortedDictionary<string, string> sortedParamMap) { StringBuilder builder = new StringBuilder(); if (sortedParamMap.Count == 0) { builder.Append(""); return builder.ToString(); } foreach (KeyValuePair<string, string> kvp in sortedParamMap) { builder.Append(this.PercentEncodeRfc3986(kvp.Key)); builder.Append("="); builder.Append(this.PercentEncodeRfc3986(kvp.Value)); builder.Append("&"); } string canonicalString = builder.ToString(); canonicalString = canonicalString.Substring(0, canonicalString.Length - 1); return canonicalString; } } class ParamComparer : IComparer<string> { public int Compare(string p1, string p2) { return string.CompareOrdinal(p1, p2); } } 


We will use as follows:
 /*...*/ SignRequestHelper signRequestHelper = new SignRequestHelper(Settings.Default.MyAWSKeyID, Settings.Default.MyAWSSecretKey, Settings.Default.Destination); /*....*/ XmlDocument document = RetrieveXmlResponse(this.signRequestHelper.Sign(requestString)); /*...*/ private static XmlDocument RetrieveXmlResponse(string url) { try { WebRequest request = HttpWebRequest.Create(url); WebResponse response = request.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(response.GetResponseStream()); return doc; } catch (Exception e) { Console.WriteLine("Caught Exception: " + e.Message); Console.WriteLine("Stack Trace: " + e.StackTrace); } return null; } 

At first I tried to parse the XmlDocument that came from the response (which was wrong at the root and took a lot of time). Then I remembered the proxy in which was the class ItemLookupResponse (the root element of the responsa XML) and deserialization . And everything was decided many times simpler:
 public ItemLookupResponse RetrieveItemDetails(string itemID) { ItemLookupResponse result = new ItemLookupResponse(); string requestString = String.Format(Settings.Default.RequestFormatString, Settings.Default.ServiceParameter, Settings.Default.VersionParameter, Settings.Default.OperationParameter, ResponseGroup.Large.ToString(), itemID, Settings.Default.AssociateTagParameter); XmlDocument document = RetrieveXmlResponse(this.signRequestHelper.Sign(requestString)); var ser = new XmlSerializer(typeof(ItemLookupResponse), Settings.Default.NamespaceURI); try { var wrapper = (ItemLookupResponse)ser.Deserialize(new XmlNodeReader(document.DocumentElement)); result = wrapper; } catch (Exception ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Stack Trace: " + ex.StackTrace); } return result; } 

As a result, we get the ItemLookupResponse object with all the properties we need. Prices we can pull from the item Item
 Item item = GetItem(result); /* item.OfferSummary.LowestCollectiblePrice; item.OfferSummary.LowestNewPrice; item.OfferSummary.LowestRefurbishedPrice; item.OfferSummary.LowestUsedPrice; */ 

All we wanted, we got. Immediately make a request for an ItemLookup is not limited to one & ItemId = B0047DVWLW there may be more, at times. ItemID is the so-called ASIN (Amazon Standard Identification Number). A little more searching ItemLookupResponse in the eyes rushed section:
 <SimilarProducts> <SimilarProduct> <ASIN>B0013FRNKG</ASIN> <Title> Apple iPad 2 MC769LL/A Tablet (16GB, WiFi, Black) 2nd Generation </Title> </SimilarProduct> <SimilarProduct> <ASIN>B003D8GAA0</ASIN> <Title> 3 Pack of Premium Crystal Clear Screen Protectors for Apple iPad </Title> </SimilarProduct> /*..........*/ 

Those. In the XML response, a set of similar devices still comes. Therefore, an idea appeared to retrieve all necessary devices and their similar products from the database via RetrieveItemDetails (string itemID) (we write the recursive method). As you probably noticed, under ASIN = B003D8GAA0, the screen protector that we do not need is hiding (and, accordingly, we filter such elements in response).
Search for similar devices
 private void GetAllSimilarItemDetails(string asin) { try { ItemLookupResponse lookupResponse = RetrieveItemDetails(asin); if (!devicesCollection.ContainsKey(asin)) { devicesCollection.Add(asin, lookupResponse); } else { return; } foreach (var item in lookupResponse.Items) { foreach (var internalItem in item.Item) { bool isContainNeededNode = false; if (internalItem.ItemAttributes.Title.ToLower().Contains("device_title")) { foreach (var node in internalItem.BrowseNodes.BrowseNode) { if (node.Name == "Tablets" || node.Name == "Electronics") { isContainNeededNode = true; } } if (isContainNeededNode) { foreach (var similarItem in internalItem.SimilarProducts) { GetAllSimilarItemDetails(similarItem.ASIN); } } else { break; } } } } } catch (Exception ex) { throw ex; } } 



Alert


As an alert was selected mail and twitter. A timer was set and checked the prices for devices at a certain interval, and if the price was different from the moment of the last check or the minimum set for soap, a letter flew away and a certain account on Twitter posted a message (via Twitterizer ).

In perspective


If desire and time allows, there is an idea to rewrite this whole thing in the Windows Service, which will monitor the necessary purchases by the specified parameters. And write a responsive tweetbot which will be on mention with a specific tag and parameters to give the user the necessary info.

Result


And now about the most important thing, the device was bought and presented to the wife. Everyone is happy!

Links


Source: https://habr.com/ru/post/151917/


All Articles