Using the API in PHP

After an example of the eBay Finding API and the Amazon Product Advertising API in previous posts, I finally want to show an example of the API.

First of all you need to register for a free developer account.

Then you can start building the API request URL:

Now let’s see what the individual parameters mean:

  • GeneralSearch: we need the operation GeneralSearch for our keyword-based search.
  • apiKey: you get this API key in your developer account.
  • trackingId: you need to request a tracking ID from to earn some money with your traffic.
  • subTrackingId: choose any additional code here you want to use as optional tracking (e. g. for special campaigns).
  • categoryId: the category you want to search in (leave empty to search in all categories).
  • keyword: your search keywords. Make sure you use utf8_decode if the keywords are in UTF-8.
  • pageNumber: for the first request you set this to 1 and increase it in previous requests if you need more items.
  • numItems: here you can choose how many items (maximal 100) are returned per request.
  • hybridSortType: choose if you want the result to be sorted by relevance or price.
  • hybridSortOrder: choose if you want the result to be sorted ascending or descending.

That’s all: we just need to pass this URL again to the small function we used already in the eBay Finding API and the Amazon Product Advertising API examples and receive the XML response data:

 * Returns the SimpleXML object.
 * @param string $url The URL to receive the XML document.
 * @return string The SimpleXML object.
function getXml($url) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_TIMEOUT, 3);
	$result = curl_exec($ch);

	return simplexml_load_string($result);

As you can see the API is very easy to handle as it is also the smallest of these three APIs.

Did you use the API yourself already?
Do you know other interesting online shopping APIs?

This post is also available in Deutsch.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>