I love a bargain! And who doesn’t? Every time I buy anything online I find myself looking out for vouchers, promo-codes, or even cheaper prices on other sites.

Nine times out of ten I end up buying what I want from Amazon for convenience and it’s normally cheaper anyway.

But buying from Amazon and not trying to get the best deals out there seems a bit silly to me. Amazon updates their prices many times a day, and being frugal as I am I want to make sure I buy whatever I want when it’s on its lowest price, even if it takes longer for me to get what I want.

To solve this problem I decided to write an application that accepts an Amazon product URL and then polls Amazon to get pricing information. If it finds the prices are lower than the last time it checked, the app then sends an SMS telling me the new price, and by how much it’s gone down. It also gives me a shortened link to the item so I can buy it there and then.

What we’ll need

To complete our bargain-hunter hack I have used Visual Studio 2013 and a few other bits.

A Twilio number (sign up for a free Twilio account here)

.NET 4.5 & ASP.NET MVC 5

Entity Framework 6

An Amazon account

A bit.ly account

The first three items will most likely already be available in any .Net development environment, but you can get it from here if you don’t already have it. Additionally we will download a few Nuget packages as as we progress.

If you don’t want to have to type all the code, feel free to download it from here and all you will need to do is add some environment variables to your system.

Getting your Amazon credentials

I’m pretty sure by now you already have an Amazon account but for this hack we will need access to their Product Advertising API to fetch product prices. So when you get to the website, make sure you click the link Sign Up Now, and complete the registration process as you will need this in order to make requests to the API.

The API requires a combination of three user credentials to make requests. We can get the first two by heading to the Amazon AWS Management Console and generating a couple of keys.

When the page is loaded, click the button Create New Key and click the link Show Access Key.

This will give you an Access Key ID and a Secret Access Key. Make a note of both as we will be using them in a bit.

Next we need get the third user credential, which is your associate tracking ID. You can get one by going to the Amazon Associates page and logging in with your Amazon account details. Once you’re logged in copy your Tracking ID, which is displayed on the top left.

You’ve now got all the Amazon credentials we will need to complete this hack.

Getting your Bitly credentials

Bitly is the URL shortening service we will use when our bargain hunting application detects a price drop.

Head to Bitly’s website and sign in. You can use your Twitter or Facebook account to sign in or just create a new account if you don’t already have one.

When you’re logged in head to the Settings page and click on Advanced. Scroll to the bottom of the page and take a note of the Login and API Key.

Setting up the initial project

Let’s start by creating a new Solution in Visual Studio by clicking on New Project, and under the tab Visual C# > Web choosing ASP.NET Web Application. Under Name and Solution Name enter BargainHunter. You can save the project to wherever you usually keep your code, I’ve saved mine to the Desktop.

On the next screen, Visual Studio will prompt us to choose what kind of project we want to create. Select the Empty template and check the MVC checkbox to create an empty MVC project.

Once the project is created, right click the project name in the Solution Explorer and choose the option Manage Nuget Packages. This is where we’re going to install all of our dependencies.

Start by installing Twilio, the helper library that will make it easier for us to communicate with Twilio’s API.

Repeat the process for the following libraries:

EntityFramework – is the ORM that will help us communicate with the database where our deals will be stored.

Bitly.Net API Wrapper – Is a wrapper to the Bitly API which we will use to generate shortened URLs.

Hangfire – Is an amazing set of open-source libraries that will help us create, process and manage our background jobs.

AmazonItemLookup – Is a small library that makes it easier for you to communicate with Amazon Advertising API. This wrapper is not officially supported by Amazon.

Once you have installed them all click on the Updates tab and click the Update All button. This will guarantee we’re running the latest version on everything we’re using.

To bootstrap Hangfire, we will follow its documentation and create a new file on the root of our project called Startup.cs.

In that file add the following initialization code: