Using the eBay Finding API in PHP

While working on a client project I needed to connect the website to the eBay Finding API to show eBay items on the website.

In the following I want to show how to get eBay items from the eBay Finding API based on a keyword search.

First of all you need to join the free eBay developers program to get your application ID. If you additionally want to earn some money with your eBay traffic – and probably that’s the reason why you want to integrate eBay items in your website ;-) – you also need to apply to the eBay partner network.

After you have been registered in the eBay developers program and partner network, you can use following URL in your request to query for eBay items:

Now let’s see what the individual parameters mean:

  • OPERATION-NAME: the name of the operation of the eBay Finding API you want to call. For the keyword search we choose findItemsByKeywords.
  • SERVICE-VERSION: the API version you’re using (the current one is 1.0.0 right now).
  • GLOBAL-ID: here you need to include the ID of the eBay site you’re using.
  • SECURITY-APPNAME: the application ID you got from the eBay developers program website.
  • RESPONSE-DATA-FORMAT: you can choose here how the data should be returned. I use XML, but you also could choose JSON or NV (name-value pair).
  • REST-PAYLOAD: just specify this without a value after the standard headers above.
  • affiliate.networkId: you get this ID from the eBay partner network.
  • affiliate.trackingId: you get this ID from the eBay partner network.
  • affiliate.customId: choose any additional code here you want to use as optional tracking (e. g. for special campaigns).
  • paginationInput.entriesPerPage: here you can choose how many items (maximal 100) are returned per request.
  • paginationInput.pageNumber: for the first request you set this to 1 and increase it in previous requests if you need more items.
  • keywords: last but not least you include your search keywords here. Make sure you use utf8_decode if the keywords are in UTF-8.

Finally we just need to receive our XML data. Therefore I use this simple function to get the data from the URL and load the XML document:

 * 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);

Of course, there is very much more you can do with the eBay APIs. For example I also needed to get items by category as well as the most watched items. That’s also pretty easy. If you need more, you can even do the whole buying process directly through the eBay APIs: this way the user does not need to leave your website at all to buy an item.

Finally I want to say that in fact the eBay APIs are very big and complex APIs, but the documentation is quite good, too. There are much worse examples of big APIs (see also my post about the Amazon Product Advertising API).

Did you use the eBay APIs yourself already?

This post is also available in Deutsch.

2 thoughts on “Using the eBay Finding API in PHP

  1. Pingback: Using the Amazon Product Advertising API in PHP |

  2. Pingback: Using the API in PHP |

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>