Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changes to eBay API

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
Recently eBay apparently made some changes to their API that caused one of my sites to not show the listing that it had before. Is anyone familiar with it enough to tell me what I need to do to get the code working again?

JavaScript:
<script language="JavaScript" src="[URL unfurl="true"]http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=pm%23fack%7Eoik&bdrcolor=FFCC00&catid=<?=$LinkID?>&cid=0&eksize=1&encode=ISO-8859-1&endcolor=FF0000&endtime=y&fbgcolor=FFFFFF&fntcolor=000000&fs=0&hdrcolor=FFFFCC&hdrimage=1&hdrsrch=y&img=y&lnkcolor=0000FF&logo=2&num=50&numbid=y&paypal=y&popup=y&prvd=1&query=Packard&r0=3&sacategoryin=<?=$LinkID?>&shipcost=y&siteid=0&sort=MetaEndSort&sortby=endtime&sortdir=asc&srchdesc=y&tbgcolor=FFFFFF&title=<?=$CategoryText?>&tlecolor=FFCE63&tlefs=0&tlfcolor=000000&track=2190672&watchcat=6389&width=800"></script>[/URL]
</center>
<div id="itemContent"></div>

A couple parameters are being passed dynamically from my site's database. Thank you in advance for any help you may be able to provide!
 
what's not working about it?

when I just used that url I got a valid result (some js code) from ebay. I suspect it won't do much (even if I did trust it enough to allow it to run) without valid credentials and categories.
 
It is not pulling up anything. It shows the styles and eBay form where the listing used to be but there is nothing in it.
 
happy to try to help.

what is the name of the eBay API you are have been using (they have loads and I'm not familiar enough with all those that are deprecated).

can you provide an actual url (with the link and text in) so we can see the output? or direct us to a site where the issue can be seen?
 
This site was created many, many years ago so I do not know if they even used names for the APIs then. As I recall, it was the only choice which I know isn't much help. I went through their current documentation but, as I am not a JavaScript programmer, it was unintelligible to me. You can see my site at Packards California.

Here are the values as the site sees them:

JavaScript:
<script language="JavaScript" src="[URL unfurl="true"]http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=pm%23fack%7Eoik&bdrcolor=FFCC00&catid=,33559&cid=0&eksize=1&encode=ISO-8859-1&endcolor=FF0000&endtime=y&fbgcolor=FFFFFF&fntcolor=000000&fs=0&hdrcolor=FFFFCC&hdrimage=1&hdrsrch=y&img=y&lnkcolor=0000FF&logo=2&num=50&numbid=y&paypal=y&popup=y&prvd=1&query=Packard&r0=3&sacategoryin=,33559&shipcost=y&siteid=0&sort=MetaEndSort&sortby=endtime&sortdir=asc&srchdesc=y&tbgcolor=FFFFFF&title=&tlecolor=FFCE63&tlefs=0&tlfcolor=000000&track=2190672&watchcat=6389&width=800"></script>[/URL]
</center>
<div id="itemContent"></div>
 
Hi

without knowing more about the API you are trying to use, or which of the new APIs you are trying to use, it's proving difficult to help. I've tried searching archives back to 2006 but cannot find an API reference that matches the one you are using. Perhaps you have lab-notes on it from when you first implemented it?

What I did notice was:

1. there is a prepended comma in the catID field (twice).
2. the categoryID 33559 for the US ebay site no longer seems to be listed as valid.

but rather than fix this it is probably better to log into your ebay developer account and use one of their code builders to recreate the link with the new APIs for banner listings (assuming that is what you are trying to achieve).
 
Perhaps it is just a matter of invalid category IDs. I hadn't thought of that but will look into it.
 
As I'm traveling at the moment, I was finally able to get online into my database to check and categoryID 33559 is indeed legitimate for eBay Motors->Parts & Accessories->Car & Truck Parts->Brakes. The prepended comma is, or at least was, legitimate and is a placeholder for values that may or may not be there, depending on the type of search being done.
 
Fair enough. When I downloaded the US cat id database 33559 was not in it.

If you know that a prepended comma is legitimate do you now also know what the API was that you are using so we can review the documentation and try to help?

If not perhaps you could look at the current APIs and determine whether any of those are suitable for you?
 
The closest I've been able to find is for keywords only but I need to also view by the category and subcategory IDs. The base category is 6398 (Packard automobiles), then subcategories for parts and accessories for them. The simple code I posted above was working but now it seems that long and convoluted code is needed. The code below presents totally unformatted rows of data by keyword only so it picks up Packard autos, Hewlett-Packard, Packard Bell and anything else with the word in it. I'm not too worried about the appearance as I can change it to divs and styles but I cannot find anything suitable that brings up only the data needed! You can see where I added url += "&categoryId=6398"; but it apparently does nothing with his particular API.

JavaScript:
<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.galleryURL;
    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 = [
  {"paramName":"Currency",
   "paramValue":"USD"},
  {"name":"FreeShippingOnly",
   "value":"false",
   "paramName":"",
   "paramValue":""},
  {"name":"ListingType",
   "value":["AuctionWithBIN", "FixedPrice"],
   "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);

var url = "[URL unfurl="true"]http://svcs.ebay.com/services/search/FindingService/v1";[/URL]
    url += "?OPERATION-NAME=findItemsByKeywords";
    url += "&SERVICE-VERSION=1.0.0";
    url += "&SECURITY-APPNAME=DonPiers-4a1e-40ef-9c6c-429f470ccb6b";
    url += "&GLOBAL-ID=EBAY-US";
    url += "&RESPONSE-DATA-FORMAT=JSON";
    url += "&callback=_cb_findItemsByKeywords";
    url += "&REST-PAYLOAD";
    url += "&keywords=Packard";
    url += "&paginationInput.entriesPerPage=50";
    [COLOR=red][b]url += "&categoryId=6398";[/b][/color]
    url += urlfilter;

// Submit the request
s=document.createElement('script'); // create script element
s.src= url;
document.body.appendChild(s);
</script>
 
using jQuery I got meaningful results with this code

Code:
	var urlfilter = '';
	var url = "[URL unfurl="true"]http://svcs.ebay.com/services/search/FindingService/v1";[/URL]
    url += "?OPERATION-NAME=findItemsAdvanced";
    url += "&SERVICE-VERSION=1.0.0";
    url += "&SECURITY-APPNAME=DonPiers-4a1e-40ef-9c6c-429f470ccb6b";
    url += "&GLOBAL-ID=EBAY-US";
    url += "&RESPONSE-DATA-FORMAT=JSON";
    url += "&REST-PAYLOAD";
    url += "&keywords=Packard";
	url += "&descriptionSearch=TRUE";
    url += "&paginationInput.entriesPerPage=50";
    url += "&categoryId=6398";
    url += urlfilter;

// Submit the request
$.ajax({
	url: url,
	dataType:'jsonp',
	success: function(data){
		alert("returned " + data.findItemsAdvancedResponse[0].searchResult[0]['@count'] + " items")
		console.log(data.findItemsAdvancedResponse[0].searchResult[0].item);
	}
})
by meaningful I got zero items as is. but when I removed the keyword I got 21 items, suggesting that the combination of keyword and categoryID is reducing the find-count to zero.

which would/might also explain your current issue?
 
I am not getting any results from it. Did you replace all the code with this bit or only the related sections, leaving the rest alone? Should it also be able to handle keywords and subcategories? That is what I will need.
 
the above handles categories and keywords. i suspect subcategories are not real but just the same level as categoryId.

as said I got no results with that query, but suppressing the keywords I got 21. I suspect that there is nothing for sale in your desired combination of keyword and category.


 
There are always Packard cars on eBay so that's not it and it does need to be able to handle two categories. The main one is for Packard which, by itself, will pull up a listing of cars; the other is for the type of part if looking for one. Using only 33559 by itself, for example, will pull up brakes for any and all makes and that's not what's needed. Using a keyword can be used, for example, to limit the search to a given year so I'm glad it can do that. I'm about to leave for the airport to catch a plane but will look into it more once I'm back home.
 
you can add categories. all i was saying is that i suspect canonically all subcategories are actually just categories within the database.

i recall that categories can be added by comma delimited values without spaces in between. keywords can also be added but _must_ be url encoded in the manner that you are using them. how you add them (commas, spaces, quotes etc) has different meanings to eBay in terms of boolean logic.

adjusting the query a little to the below, I get meaningful results for brakes for Packard cars.

I'm not sure what more I can add - it all seems to work (obviously you'll have to write an xml tree walker to map the fields to your display but that's easy given that you have jQuery loaded). using this jQuery method obviates the need to specify a url callback, which is a small advantage. if the query is still not returning meaningful results for you then it's either because the combination doesn't produce a result set or something else wrong at eBay. Remember when you query on eBay on the web if you don't get a result set match they use a related item search to pad the results. Perhaps you could do the same?

Code:
<!DOCTYPE HTML>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
var url = "[URL unfurl="true"]http://svcs.ebay.com/services/search/FindingService/v1";[/URL]
    url += "?OPERATION-NAME=findItemsAdvanced";
    url += "&SERVICE-VERSION=1.0.0";
    url += "&SECURITY-APPNAME=DonPiers-4a1e-40ef-9c6c-429f470ccb6b";
    url += "&GLOBAL-ID=EBAY-US";
    url += "&RESPONSE-DATA-FORMAT=JSON";
    url += "&REST-PAYLOAD";
    url += "&keywords=Packard";
    url += "&descriptionSearch=1";
    url += "&paginationInput.entriesPerPage=50";
    url += "&categoryId=33559";

// Submit the request
$.ajax({
	url: url,
	dataType:'jsonp',
	success: function(data){
		document.write("returned " + data.findItemsAdvancedResponse[0].searchResult[0]['@count'] + " items<br/>");
		var it = data.findItemsAdvancedResponse[0].searchResult[0].item;
		for (var i = 0; i<it.length; i++){
			var str = JSON.stringify(it[i]);
			document.write( str.replace(/,"/g,',<br>"') );
			document.write('<hr/>');
		}
	}
});
</script>
</head>
<body>
</body>
</html>
 
Great, it is now pulling up results and they seem to make sense! I've not been able to figure out how to apply the appearance templates and filters that it had but below is what I have so far. Once that's resolved, I can test it to be sure it handles multiple categoryId values and that it uses both of them, not just one or the other, then add back in the keyword search facility. Right now if I submit a categoryId dynamically, it does not give results (with <?=$LinkID?> rather than hard coded to 33559). The code I posted here originally did all that automatically so it's odd that they would have gotten rid of something that did the job so well.

JavaScript:
<script>
// Parse the response and build an HTML table to display search results
function _cb_findItemsAdvanced(root) {
  var items = root.findItemsAdvancedResponse[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;
    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 = [
  {"paramName":"Currency",
   "paramValue":"USD"},
  {"name":"FreeShippingOnly",
   "value":"false",
   "paramName":"",
   "paramValue":""},
  {"name":"ListingType",
   "value":["AuctionWithBIN", "FixedPrice"],
   "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);

var url = "[URL unfurl="true"]http://svcs.ebay.com/services/search/FindingService/v1";[/URL]
	url += "?OPERATION-NAME=findItemsAdvanced";
	url += "&SERVICE-VERSION=1.0.0";
	url += "&SECURITY-APPNAME=DonPiers-4a1e-40ef-9c6c-429f470ccb6b";
	url += "&GLOBAL-ID=EBAY-US";
	url += "&RESPONSE-DATA-FORMAT=JSON";
	url += "&REST-PAYLOAD";
	url += "&keywords=Packard";
	url += "&descriptionSearch=1";
	url += "&paginationInput.entriesPerPage=50";
	url += "&categoryId=33559";

// Submit the request
$.ajax({
	url: url,
	dataType:'jsonp',
	success: function(data){
		document.write("returned " + data.findItemsAdvancedResponse[0].searchResult[0]['@count'] + " items<br/>");
		var it = data.findItemsAdvancedResponse[0].searchResult[0].item;
		for (var i = 0; i<it.length; i++){
		var str = JSON.stringify(it[i]);
		document.write( str.replace(/,"/g,',<br>"') );
		document.write('<hr/>');
		//document.write(buildURLArray(filterarray)));
		}
	}
});
</script>
 
you don't need the buildarray function anymore and the callback function is not being used at all.

if you want it to be used (in specie) then in the success: component of the ajax call do this

Code:
success:  function(data){ 
 var table = $('<table width="100%" border="0" cellspacing="0" cellpadding="3" />');
 var tb = $('<tb/>');
 var it = data.findItemsAdvancedResponse[0].searchResult[0].item;
 for (var i = 0; i<it.length; i++){
    var item     = it[i];
    var title    = item.title;
    var pic      = item.galleryURL;
    var viewitem = item.viewItemURL;
    if (null != title && null != viewitem) {
     tb.append('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' +
      '<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td></tr>');
    }
  }
 table.append(tb).appendTo($('body'));
}
 
I needed to add a line:

JavaScript:
var url = "[URL unfurl="true"]http://svcs.ebay.com/services/search/FindingService/v1";[/URL]
	url += "?OPERATION-NAME=findItemsAdvanced";
	url += "&SERVICE-VERSION=1.0.0";
	url += "&SECURITY-APPNAME=DonPiers-4a1e-40ef-9c6c-429f470ccb6b";
	url += "&GLOBAL-ID=EBAY-US";
	url += "&RESPONSE-DATA-FORMAT=JSON";
	[b][COLOR=red]url += "&callback=_cb_findItemsAdvanced";[/color][/b]
	url += "&REST-PAYLOAD";
	url += "&keywords=Packard";
	url += "&descriptionSearch=1";
	url += "&paginationInput.entriesPerPage=50";
	url += "&categoryId=<?=$LinkID?>";

and now it gives reasonable default results. It's still unformatted but at least it is HTML so I have something with which to work.
 
as above - you don't need the callback if you use my code.
not sure why it's not recognising my [ignore]
Code:
[/ignore]tags
be wary of mixing the callback parameter and the inherent callback from the jquery.ajax call.
 
Yes, I had just added that but it does not appear to be using the HTML table as any changes I make to test do not show up. For example I exaggerated the width of the table to a narrow 50% but it was still full width on the site.

Also, trying to use two categoryId values together pulls up nothing at all but without being able to use both, selecting a category from the site's menu pulls up everything for any make of car in that category.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top