Find Gifts By Pricerange in Amazon Wishlists with PHP
Last year, it seems that everyone in my vicinity latched on to Amazon wishlists as a way to help everyone choose gifts. It can often be difficult to buy things for other adults, especially if you tend to stick to a given price range.
A few weeks ago, I posted some code for displaying the data in a wishlist. That's a quick way to get a single page from a wishlist, but what I often get asked for is a list between, say, $15 and $25. Rather than try to dig through my main wishlist and select items, I wrote up a solution in PHP. (You'll have to excuse the "br" tags in the code. Wordpress is adding them and I have to figure out how to suppress them, but don't really look forward to tackling it right now).
Anyway, beyond the geek factor, this appeals to me because I have lots of items on my list that have been on there long enough that I don't necessarily remember putting on there. That happens when your list spans 6 pages. That is a good thing though because it means I can be surprised by the gifts, even when I picked them out myself.
This is also a way to get just a little deeper into the Wishlist API's.
Here's a sample page that shows my main wishlist items between $15 and $25.
Note the end of the URL where min_price and max_price define the ranges. Now, here's how the page is built.
The above code sets up your api key and the list id (see the previous article for getting that).
Now, we convert the price ranges to the format that Amazon wants. They are looking for $15 as 1500. Then, grab the first page of the list using SimpleXML and grab the one bit of data we need to move forward: the number of pages in the list.
Then the biggest chunk of the code. Looping through each page of the complete list, grab the page data. Then pull the items out and check the lowest new price. I used the lowest new price to avoid some of the crap that shows up in the used stuff (like missing pieces, etc.). Personally, if someone is buying me a gift and was planning on spending a dollar amount, I'd prefer that they buy used, but it's more stable to do it this way.
If the price falls between the ranges, I print out a line with the product information.

