- Purpose
- Getting Started
- In Session
- Creating Listings
- Finding Listings
- Photo Browser
- Conclusion
Finding Listings
Many users of the eBay SDK will want to utilize its functionality to enable them to tie back-end inventory systems to eBay and automate the creation of auction listings. That said, the ability to query auction listings and aggregate results is quite valuable as well, and the SDK enables those capabilities in a variety of ways. One of the most common ways would be searching by description. This is done through instances of GetSearchResultsCall, which returns collections of items. Again, we'll need to initialize some search objects:
GetSearchResultsCall searchResultsCall = new GetSearchResultsCall(session); IItemFoundCollection results = null; searchResultsCall.Query = "apples and oranges"; searchResultsCall.MaxResults = 16; searchResultsCall.SearchInDescription = true;
In this example, we're stating that the maximum number of returns will be 16. To iterate over more than that, we need to use more calls and skip ahead with each subsequent call, like this:
results = searchResultsCall.GetSearchResults(); int retrieved = results.Count; while(results.Count > 0 && retrieved < 321) { foreach (IItemFound result in results) { processItem(result.Item); } if(retrieved < 16) break; searchResultsCall.Skip = retrieved; results = searchResultsCall.GetSearchResults(); retrieved += results.Count; }
This code will retrieve 320 listings, 16 at a time, stopping if we get less than 16 in one call. A maximum of 400 can be retrieved in a single call. Searching is reasonably quick, but retrieving and iterating over large numbers of results is slow, which means that moving the search execution into a separate thread, especially in GUI-based applications, is vital to ensuring the responsiveness of your application.
Searching for all items from a user is a similar process, but using slightly different objects. And this time there's no process for cycling over results; we can get a complete list of all the user's listings in one call. However, we do need to provide some sort of date filter. In this case, we'll look for any listings started in the last year:
GetSellerListCall searchResultsCall = new GetSellerListCall(session); IItemCollection results = null; DateTime start = new DateTime(DateTime.Now.Year-1, DateTime.Now.Month, (DateTime.Now.Day)); DateTime end = new DateTime(DateTime.Now.Year, DateTime.Now.Month, (DateTime.Now.Day+1)); searchResultsCall.StartTimeFrom = start; searchResultsCall.StartTimeTo = end; searchResultsCall.UserId = "username";
Adding +1 to Day includes any listings that were placed in the current day. Once we have the GetSellerListCall, it's possible to get the listing:
results = searchResultsCall.GetEntireSellerList(); int retrieved = results.Count; foreach (IItem result in results) { processItem(result); }
The slightly different interfaces used for retrieving listings based on a user or a description can be tricky, which means separate methods for different types of searches.