Monday, 13 October 2014

Create an Auction with TradeMe's API Using PHP

Recently I had a client wanting a catalogue website and it got me thinking how handy it would be if their products could be automatically listed on their TradeMe account at the click of a button.

Looking into this took me to the Trade Me Developer Docs. Trade Me uses OAuth to authenticate users of it's API, so I had to brush up on my knowledge on the OAuth standard. There is actually already an OAuth extension for PHP but as my requirements were basic and wanted to have a deeper understanding of OAuth, I thought I would write my own simple implementation.

My implementation consists of a base class 'oauthRequest' which handles OAuth API requests and responses, and, extending this, our Trade Me-specific functionality in the 'trademeApiRequest' class. Keeping the Trade Me functionality in a separate class, I am hoping to reuse the base 'oauthRequest' class for other lightweight OAuth APIs.

The PHP source code for my basic Trade Me API integration is available for download from GitHub - please see the link below.

Download Source Code