skip to Main Content

I am using eBay API’s findItemsByKeywords call to search for items. I have tried accessing the returned item’s parameters like:

var price = item.price;
var condition = item.condition;

However, they come up as undefined. The eBay API reference doesn’t seem to explain how this information can be parsed and then displayed.

<div id="api"></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.galleryURL;
    var viewitem = item.viewItemURL;
    var price    = item.price;
    var condition= item.condition;
    if (null != title && null != viewitem)
    {
      html.push(
        '<tr id="api_microposts"><td>'
         + '<img src="' + pic + '" border="0" width="190">' + '<a href="' + viewitem + '" target="_blank">' + title + 
         '</a>' + '<br>' + price + '</td></tr>');
    }
  }
  html.push('</tbody></table>');
  document.getElementById("api").innerHTML = html.join("");




// 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 parameter 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);

url += urlfilter;



}
</script>


<!--
Use the value of your appid for the appid parameter below.
-->

<script src=http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=*APP ID GOES HERE*&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=3&outputSelector=GalleryInfo&outputSelector=AspectHistogram&itemFilter(0).name=Condition&itemFilter(0).value(0)=New&itemFilter(1).name=MaxPrice&itemFilter(1).value=450.00&itemFilter(1).paramName=Currency&itemFilter(1).paramValue=USD&itemFilter(2).name=MinPrice&itemFilter(2).value=350.00&itemFilter(2).paramName=Currency&itemFilter(2).paramValue=USD&itemFilter(3).name=ListingType&itemFilter(3).value=FixedPrice&keywords=Moto%20x%2016gb%20unlocked>

</script>

2

Answers


  1. Not sure why condition isn’t coming up: http://developer.ebay.com/Devzone/finding/CallRef/types/SearchItem.html

    Seems you’re looking for unitPrice and condition.conditionDisplayName

    Login or Signup to reply.
  2. Ebay’s examples aren’t very helpful. You can do your debugging using their quickstart example and a judicious use of JSON.stringify() to see what the return objects look like.

    var price = item.sellingStatus[0].currentPrice[0]["__value__"];
    var condition = item.condition[0].conditionDisplayName[0];
    

    http://developer.ebay.com/quickstartguide/sample/js/default.aspx

    (Note that you might want convertedCurrentPrice if you’re doing non-local-currency queries.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search