Skip to main content
Published: December 04 2014, 3:07:00 AMUpdated: August 29 2022, 3:36:39 PM

How do I get all my active listings using Java SDK?

1. GetSellerList

    Specify the EndTimeFrom as current date and EndTimeTo as current date + 30 days. This will return even GTC items. Please note that there's a chance of getting the same item twice if you add more than 30 days. Because some GTC items may get automatically relisted while you are fetching the items.

 

import java.util.Calendar;
import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.TimeFilter;
import com.ebay.sdk.call.GetSellerListCall;
import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
import com.ebay.soap.eBLBaseComponents.ItemType;
import com.ebay.soap.eBLBaseComponents.ListingStatusCodeType;
import com.ebay.soap.eBLBaseComponents.PaginationType;
import com.ebay.soap.eBLBaseComponents.SellingStatusType;

public class GetAllActiveListingsGSL

 public static void main(String args[])
 {  
  GetAllActiveListingsGSL gsl=new GetAllActiveListingsGSL();  
  try
  {  
     ApiContext apiContext = new ApiContext();
        ApiCredential cred = apiContext.getApiCredential();
        cred.seteBayToken('INSERT_YOUR_TOKEN_HERE');
        apiContext.setApiServerUrl('https://api.ebay.com/wsapi');
        apiContext.setSite(com.ebay.soap.eBLBaseComponents.SiteCodeType.US);
  
        GetSellerListCall api = new GetSellerListCall (apiContext);

     boolean hasMoreItems=true;
     int pageNumber=1;
     int itemCount = 0;
  
     Calendar calFrom = Calendar.getInstance();
     calFrom.add(Calendar.MINUTE, -5);
     Calendar calTo = Calendar.getInstance();
     calTo.add(Calendar.DAY_OF_MONTH, 32);
  
     TimeFilter tf = new TimeFilter(calFrom, calTo);
     api.setEndTimeFilter(tf);

     DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {DetailLevelCodeType.RETURN_ALL };
     api.setDetailLevel(detailLevels);
  
     PaginationType pt = new PaginationType();
     pt.setEntriesPerPage(200);
     api.setPagination(pt);      
  
  while(hasMoreItems)
  {
         
    pt.setPageNumber(pageNumber);
   
          ItemType[] activeItems = api.getSellerList(); //Execute API call
   
    hasMoreItems=api.getHasMoreItems();   
    System.out.println('Page Number:'+ pageNumber);   
    System.out.println('Total number of Items to retrieve:'+api.getReturnedItemCountActual()); 
         
    for (ItemType item : activeItems)
   {
    SellingStatusType sellingStatus = item.getSellingStatus();
    ListingStatusCodeType listingStatus = sellingStatus.getListingStatus();
    
    if (listingStatus.equals(ListingStatusCodeType.ACTIVE))
    {
     ++itemCount;
     gsl.processActiveItem(item);
    }
    
   }  
  pageNumber++;
  
  }
  
  System.out.println('Total Number of Active Listings: '+itemCount);  
  }catch(Exception e)
  {
   e.printStackTrace();
  }  
  
 }
 
 private void processActiveItem(ItemType item)
 {
  System.out.println('ItemID:'+item.getItemID()); //Add any logic to process the active item.
 }

}

2. GetMyeBaySelling

To set <ActiveList> in GetMyeBaySelling API request.

Please note that GetMyeBaySelling has a limitation that it does not return more than 25000 items. If the number of items is more than 25000, you need to use GetSellerList.


import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.call.GetMyeBaySellingCall;
import com.ebay.soap.eBLBaseComponents.ItemArrayType;
import com.ebay.soap.eBLBaseComponents.ItemListCustomizationType;
import com.ebay.soap.eBLBaseComponents.ItemType;
import com.ebay.soap.eBLBaseComponents.PaginatedItemArrayType;
import com.ebay.soap.eBLBaseComponents.PaginationResultType;
import com.ebay.soap.eBLBaseComponents.PaginationType;

public class GetAllActiveListingsGMS
{
 
 public static void main(String args[])
 {
  GetAllActiveListingsGMS gms=new GetAllActiveListingsGMS();
  
   try{
     ApiContext apiContext = new ApiContext();
        ApiCredential cred = apiContext.getApiCredential();
        cred.seteBayToken('INSERT_YOUR_TOKEN_HERE');
        apiContext.setApiServerUrl('https://api.ebay.com/wsapi');
        apiContext.setSite(com.ebay.soap.eBLBaseComponents.SiteCodeType.US);
  
        GetMyeBaySellingCall api = new GetMyeBaySellingCall (apiContext);  
       
     ItemListCustomizationType activeList=new ItemListCustomizationType();
     activeList.setInclude(true);   
    
     PaginationType pt = new PaginationType();
     pt.setEntriesPerPage(200);
    
     int pageNumber=1;
     int totalNumberOfPages=1;
    
     activeList.setPagination(pt);
    
     api.setActiveList(activeList);
    
     while(totalNumberOfPages>=pageNumber)
     {
  
     pt.setPageNumber(pageNumber);  
    
           api.getMyeBaySelling();
          
           PaginatedItemArrayType activeItems = api.getReturnedActiveList();
           PaginationResultType paginationResult=activeItems.getPaginationResult();
           totalNumberOfPages=paginationResult.getTotalNumberOfPages();
           System.out.println('Total Number of active items: '+paginationResult.getTotalNumberOfEntries());
         
          
           if(activeItems!=null)
           {
            ItemArrayType itemArray=activeItems.getItemArray();
           
            ItemType[] items= itemArray.getItem();
           
            for(ItemType item: items)
            {
             gms.processActiveItem(item);
            }
           }
          
           pageNumber++;
     }  
          
          }catch(Exception e)
          {
           e.printStackTrace();//Add required exception handling
          }   
  
  
 }
 
 private void processActiveItem(ItemType item)
 {
  System.out.println('ItemID: '+item.getItemID()); // Add any logic to process the item
 }

}
   

 

 

How well did this answer your question?
Answers others found helpful