This is how to get large photos with the eBay Finding API.

People across the web are asking how to get larger images when using the eBay Finding API. eBay developer support says it is not possible. So why are there API calls named pictureURLLarge and pictureURLSuperSize?  It turns out you can get high resolution images with the Finding API. Through trial and error I figured it out.  Here is how it is done:

In each of the three examples below replace MyAppID with your actual app ID use the same capitalization structure as shown in the examples.

Example 1
Get larger images in the Finding API with Javascript

In this example we modify eBay’s Quick Start Tutorial for the Finding API to get larger photos.

The key code changes to make are in lines 21 and 38.  In line 21  pictureURLSuperSize replaces galleryURL. In line 38 we add &outputSelector=PictureURLSuperSize between entriesPerPage and the closing “>.  

There are two less consequential changes in line 38 – I changed the keyword from  iphone%203g to iphone%6 so the search example would be relevant and I changed the API SERVICE-VERSION to 1.13.0, which is the latest version number of the Finding API at the time of writing this article.

<html>
<head>
<title>eBay Search Results</title>
<style type="text/css">body { font-family: arial,sans-serif;} </style>
</head> 
<body>
<h1>eBay Search Results</h1>
<div id="results"></div>

<script>
function _cb_findItemsByKeywords(root)
{
  var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
  var html = [];
  html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');

  for (var i = 0; i < items.length; ++i)  
  {
    var item     = items[i];
    var title    = item.title;
    var pic      = item.pictureURLSuperSize;
    var viewitem = item.viewItemURL;

    if (null != title && null != viewitem)
    {
      html.push('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' + 
        '<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td></tr>');
    }
  }
  html.push('</tbody></table>');
  document.getElementById("results").innerHTML = html.join("");
}
</script>

<!--
Use the value of your appid for the appid parameter below.
-->
<script src=http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=MyAppID&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.13.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=iphone%6&paginationInput.entriesPerPage=3&outputSelector=PictureURLSuperSize>
</script>
</body>
</html>​

Copy the code above then paste it into the source code section of this quick start tutorial, then click run sample to see it in action.

Example 2
Get larger images in the Finding API with Javascript

In this example we modify eBay’s tutorial called Getting Started with the Finding API: Finding Items by Keywords.

This is the result of the basic eBay tutorial.

This is the same result modified to get larger photos.

How did we do it?  The key code changes to make are in lines 21 and 91.  In line 21  pictureURLSuperSize replaces galleryURL. In line 91 we add url += “&outputSelector=PictureURLSuperSize”; on a new line just before url += urlfilter;

<html>
<head>
<title>eBay Search Results</title>
<style type="text/css">body { font-family: arial,sans-serif;} </style>
</head> 
<body>
<h1>eBay Search Results</h1>

<div id="results"></div>

<script>

// Parse the response and build an HTML table to display search results
function _cb_findItemsByKeywords(root) {
  var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
  var html = [];
  html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');
  for (var i = 0; i < items.length; ++i) {
    var item     = items[i];
    var title    = item.title;
    var pic      = item.pictureURLSuperSize;
    var viewitem = item.viewItemURL;
    if (null != title && null != viewitem) {
      html.push('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' + 
      '<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td></tr>');
    }
  }
  html.push('</tbody></table>');
  document.getElementById("results").innerHTML = html.join("");
}  // End _cb_findItemsByKeywords() function

// Create a JavaScript array of the item filters you want to use in your request
var filterarray = [
  {"name":"MaxPrice", 
   "value":"25", 
   "paramName":"Currency", 
   "paramValue":"USD"},
  {"name":"FreeShippingOnly", 
   "value":"true", 
   "paramName":"", 
   "paramValue":""},
  {"name":"ListingType", 
   "value":["AuctionWithBIN", "FixedPrice", "StoreInventory"], 
   "paramName":"", 
   "paramValue":""},
  ];


// Define global variable for the URL filter
var urlfilter = "";

// Generates an indexed URL snippet from the array of item filters
function  buildURLArray() {
  // Iterate through each filter in the array
  for(var i=0; i<filterarray.length; i++) {
    //Index each item filter in filterarray
    var itemfilter = filterarray[i];
    // Iterate through each parameter in each item filter
    for(var index in itemfilter) {
      // Check to see if the paramter has a value (some don't)
      if (itemfilter[index] !== "") {
        if (itemfilter[index] instanceof Array) {
          for(var r=0; r<itemfilter[index].length; r++) {
          var value = itemfilter[index][r];
          urlfilter += "&itemFilter\(" + i + "\)." + index + "\(" + r + "\)=" + value ;
          }
        } 
        else {
          urlfilter += "&itemFilter\(" + i + "\)." + index + "=" + itemfilter[index];
        }
      }
    }
  }
}  // End buildURLArray() function

// Execute the function to build the URL filter
buildURLArray(filterarray);

// Construct the request
// Replace MyAppID with your Production AppID
var url = "http://svcs.ebay.com/services/search/FindingService/v1";
    url += "?OPERATION-NAME=findItemsByKeywords";
    url += "&SERVICE-VERSION=1.0.0";
    url += "&SECURITY-APPNAME=MyAppID";
    url += "&GLOBAL-ID=EBAY-US";
    url += "&RESPONSE-DATA-FORMAT=JSON";
    url += "&callback=_cb_findItemsByKeywords";
    url += "&REST-PAYLOAD";
    url += "&keywords=harry%20potter";
    url += "&paginationInput.entriesPerPage=3";
    url += "&outputSelector=PictureURLSuperSize";
    url += urlfilter;


// Submit the request 
s=document.createElement('script'); // create script element
s.src= url;
document.body.appendChild(s);

// Display the request as a clickable link for testing
document.write("<a href=\"" + url + "\">" + url + "</a>");
</script>
</body>
</html>

Example 3
Get larger images in the Finding API with PHP

In this example we modify another eBay tutorial called Getting Started with the Finding API: Finding Items by Keywords, but this one uses PHP instead of Javascript.

How do we do it? In line 69 we add $apicall .= “&paginationInput.entriesPerPage=3”; on a new line just before $apicall .= “$urlfilter”;. Then on line 80 replace galleryURL with pictureURLSuperSize. That’s it! The code looks like this:

<?php

error_reporting(E_ALL);  // Turn on all errors, warnings and notices for easier debugging

// API request variables
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1';  // URL to call
$version = '1.0.0';  // API version supported by your application
$appid = 'MyAppID';  // Replace with your own AppID
$globalid = 'EBAY-US';  // Global ID of the eBay site you want to search (e.g., EBAY-DE)
$query = 'harry potter';  // You may want to supply your own query
$safequery = urlencode($query);  // Make the query URL-friendly
$i = '0';  // Initialize the item filter index to 0

// Create a PHP array of the item filters you want to use in your request
$filterarray =
  array(
    array(
    'name' => 'MaxPrice',
    'value' => '25',
    'paramName' => 'Currency',
    'paramValue' => 'USD'),
    array(
    'name' => 'FreeShippingOnly',
    'value' => 'true',
    'paramName' => '',
    'paramValue' => ''),
    array(
    'name' => 'ListingType',
    'value' => array('AuctionWithBIN','FixedPrice','StoreInventory'),
    'paramName' => '',
    'paramValue' => ''),
  );

// Generates an indexed URL snippet from the array of item filters
function buildURLArray ($filterarray) {
  global $urlfilter;
  global $i;
  // Iterate through each filter in the array
  foreach($filterarray as $itemfilter) {
    // Iterate through each key in the filter
    foreach ($itemfilter as $key =>$value) {
      if(is_array($value)) {
        foreach($value as $j => $content) { // Index the key for each value
          $urlfilter .= "&itemFilter($i).$key($j)=$content";
        }
      }
      else {
        if($value != "") {
          $urlfilter .= "&itemFilter($i).$key=$value";
        }
      }
    }
    $i++;
  }
  return "$urlfilter";
} // End of buildURLArray function

// Build the indexed item filter URL snippet
buildURLArray($filterarray);

// Construct the findItemsByKeywords HTTP GET call 
$apicall = "$endpoint?";
$apicall .= "OPERATION-NAME=findItemsByKeywords";
$apicall .= "&SERVICE-VERSION=$version";
$apicall .= "&SECURITY-APPNAME=$appid";
$apicall .= "&GLOBAL-ID=$globalid";
$apicall .= "&keywords=$safequery";
$apicall .= "&outputSelector=PictureURLSuperSize";
$apicall .= "&paginationInput.entriesPerPage=3";
$apicall .= "$urlfilter";

// Load the call and capture the document returned by eBay API
$resp = simplexml_load_file($apicall);

// Check to see if the request was successful, else print an error
if ($resp->ack == "Success") {
  $results = '';
  // If the response was loaded, parse it and build links  
  foreach($resp->searchResult->item as $item) {
    $pic   = $item->pictureURLSuperSize;
    $link  = $item->viewItemURL;
    $title = $item->title;
  
    // For each SearchResultItem node, build a link and append it to $results
    $results .= "<tr><td><img src=\"$pic\"></td><td><a href=\"$link\">$title</a></td></tr>";
  }
}
// If the response does not indicate 'Success,' print an error
else {
  $results  = "<h3>Oops! The request was not successful. Make sure you are using a valid ";
  $results .= "AppID for the Production environment.</h3>";
}
?>

<!-- Build the HTML page with values from the call response -->
<html>
<head>
<title>eBay Search Results for <?php echo $query; ?></title>
<style type="text/css">body { font-family: arial,sans-serif;} </style>
</head>
<body>

<h1>eBay Search Results for <?php echo $query; ?></h1>

<table>
<tr>
  <td>
    <?php echo $results;?>
  </td>
</tr>
</table>

</body>
</html>

An alternative title to this post could have been how the hell do I get the pictureURLLarge or pictureURLSuperSize API calls to run in the eBay Finding API?

I hope this helps a few of you out there.