Using the Shopping.com 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 Shopping.com API.

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

Then you can start building the API request URL:

http://publisher.api.shopping.com/publisher/3.0/rest/GeneralSearch?
	apiKey=%apikey%&
	trackingId=%trackingid%&
	subTrackingId=%subTrackingId%&
	categoryId=%categoryId%&
	keyword=%keyword%&
	pageNumber=%pageNumber%&
	numItems=%numItems%&
	hybridSortType=%hybridSortType%
	hybridSortOrder=%hybridSortOrder%

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 Shopping.com developer account.
  • trackingId: you need to request a tracking ID from Shopping.com 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);
	curl_close($ch);

	return simplexml_load_string($result);
}

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

Did you use the Shopping.com 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>