Skip to main content
Published: December 04 2014, 7:14:00 AMUpdated: November 28 2020, 12:57:12 PM

Use the below code sample for listing items on eBay India. The assumption is that you are using the eBay SDK for Java. The String "INSERT_USER_TOKEN" should be replaced with your Sandbox user token. For running the program in production, you need to use the production user token and change the Server Url to https://api.ebay.com/wsapi

 

 

package test.sdk;

import com.ebay.sdk.*;
import com.ebay.sdk.call.*;
import com.ebay.soap.eBLBaseComponents.*;

public class AddFixedPriceItemIndia
{
 
   private ApiContext createApiContext()
   {
         ApiContext apiContext = new ApiContext();
         ApiLogging apiLogging = new ApiLogging();
         apiLogging.setLogSOAPMessages(true);
      apiLogging.setLogHTTPHeaders(true);
         apiContext.setApiLogging(apiLogging);

         CallRetry cr = new CallRetry();
         cr.setMaximumRetries(3);
         cr.setDelayTime(1000); // Wait for one second between each retry-call.

         String[] apiErrorCodes = new String[]{"10007"};
         // Set trigger exceptions for CallRetry.
         cr.setTriggerApiErrorCodes(apiErrorCodes);

         // Build a dummy SdkSoapException so that we can get its Class.
         Class[] tcs = new Class[]{com.ebay.sdk.SdkSoapException.class};
         cr.setTriggerExceptions(tcs);
         apiContext.setCallRetry(cr);
         apiContext.setTimeout(120000);

         // set the server url and credentials for Sandbox
         apiContext.setApiServerUrl("https://api.sandbox.ebay.com/wsapi");
         ApiCredential cred = apiContext.getApiCredential();
         cred.seteBayToken("INSERT_USER_TOKEN");
         apiContext.setApiCredential(cred);

         // set the site
         apiContext.setSite(SiteCodeType.INDIA);

         return apiContext;
     }
  
  
  private  AddFixedPriceItemResponseType addFixedItem() throws ApiException, SdkException,Exception {

  AddFixedPriceItemCall call = new AddFixedPriceItemCall(createApiContext());

 
  ItemType item = new ItemType();
  item.setTitle("T-shirt Gap Red");
  item.setDescription("Testing item. Dont bid");

  // set the item condition depending on the value from GetCategoryFeatures
  item.setConditionID(1000);

  item.setPostalCode("560103");
  item.setListingDuration("GTC");

  // Track inventory by SKU
  item.setInventoryTrackingMethod(InventoryTrackingMethodCodeType.SKU);

  // Specify unique SKU
  item.setSKU("BASIC123456");

  // Set Payment Method to PayPal
  BuyerPaymentMethodCodeType[] arrPaymentMethods = new BuyerPaymentMethodCodeType[]{BuyerPaymentMethodCodeType.PAISA_PAY_ACCEPTED};
  item.setPaymentMethods(arrPaymentMethods);

  // Specify Quantity, Start Price and the eBay category
  item.setStartPrice(getAmount(11.0));
  item.setCountry(CountryCodeType.IN);
  item.setCurrency(CurrencyCodeType.INR);
  CategoryType category = new CategoryType();
  category.setCategoryID("177474");
  item.setPrimaryCategory(category);
  item.setQuantity(1);

  item.setShippingDetails(getShippingDetails());

  item.setDispatchTimeMax(2);
 
 
  NameValueListArrayType itemSpec = setItemSpecifics();
  item.setItemSpecifics(itemSpec);
 
 // Add pictures
  PictureDetailsType pdt = new PictureDetailsType();
  pdt.setPictureURL(new String[]{"http://i.ebayimg.com/00/s/NjQ5WDEwOTE=/z/6dwAAOxyNThTce5o/$_1.JPG?set_id=8800005007"});

  AddFixedPriceItemRequestType request=new AddFixedPriceItemRequestType();
  request.setItem(item);
 
  AddFixedPriceItemResponseType response=(AddFixedPriceItemResponseType)call.execute(request);

  return response;
}

private NameValueListArrayType setItemSpecifics()
{
 
  NameValueListArrayType itemSpec=new NameValueListArrayType();

   NameValueListType nv1 = new NameValueListType();
   nv1.setName("Brand");
   nv1.setValue(new String[]{"GAP"});
  
   NameValueListType nv2 = new NameValueListType();
   nv2.setName("Colour");
   nv2.setValue(new String[]{"Red"});

   NameValueListType nv3 = new NameValueListType();
   nv3.setName("Size Type");
   nv3.setValue(new String[]{"Regular"});

   NameValueListType nv4 = new NameValueListType();
   nv4.setName("Size (Men's)");
   nv4.setValue(new String[]{"M"});
   itemSpec.setNameValueList(new NameValueListType[]{nv1, nv2, nv3,nv4});
  
   return itemSpec;
 
}

private static ShippingDetailsType getShippingDetails() {
  ShippingDetailsType sd = new ShippingDetailsType();

  ShippingServiceOptionsType st1 = new ShippingServiceOptionsType();
  st1.setShippingService("IN_Express");
  st1.setShippingServiceCost(getAmount(30));
  st1.setShippingServiceAdditionalCost(getAmount(20));
  st1.setShippingServicePriority(1);
 
  sd.setShippingServiceOptions(new ShippingServiceOptionsType[]{st1});

  return sd;
}

private static AmountType getAmount(double amount) {
    AmountType a = new AmountType();
    a.setValue(amount);
    return a;
}  
  
  
 
 public static void main(String args[])
 {
 
    try {
     AddFixedPriceItemIndia caller=new AddFixedPriceItemIndia();
             AddFixedPriceItemResponseType response= caller.addFixedItem();
            
             System.out.println("ItemID:"+response.getItemID()+" was listed successfully");
                     
         } catch (ApiException e)
         {         
             e.printStackTrace();
         } catch (SdkException e)
         {           
             e.printStackTrace();
            
         } catch (Exception e)
         {           
             e.printStackTrace();
         }

     }
 
 
}

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