Skip to main content
Published: June 27 2007, 4:33:00 PMUpdated: November 28 2020, 3:50:36 PM

Using eBay Java SDK to execute your first AddItem API Call

 

 

 Summary

  This sample illustrates of using  eBay Java SDK framework to make AddItem call and list a Chinese auction on eBay Sandbox.  For using this sample you must have:
   1. got your sandbox keys that include three IDs (DevID, AppID, and CertID) and an API Token.
   2. obtained and installed the eBay Java SDK package.

  Attached to this article is a zipped project implementing the AddItem code.

 The source code in this Knowledge Base article is covered by this license agreement:
MIT License


 Detailed Description

Creating a standalone eBay Project named eBayApiRequest, which consists the file structure as below.   
       1. Java Source files
             ${EBAY_JAVA_SDK_HOME}/eBayApiRequest/src/ebay/sdk/AppAddItem.java
             ${EBAY_JAVA_SDK_HOME}/eBayApiRequest/src/ebay/sdk/RequestHeaderParam.java
       2. Build, batch and properties files
             ${EBAY_JAVA_SDK_HOME}/eBayApiRequest/request_param.properties
             ${EBAY_JAVA_SDK_HOME}/eBayApiRequest/build.xml
             ${EBAY_JAVA_SDK_HOME}/eBayApiRequest/run.bat 
       3. Plug your own devid, appid, cert, and token into the request_param.properties file.

Here is the AppAddItem.java souce code. 

Please refer the KB article titled Using Java SDK framework to execute your first API Call for error handling and API retrying.

/*
 * AddItem.java
 */
package ebay.dts;

import com.ebay.soap.eBLBaseComponents.*;
import com.ebay.sdk.*;
import com.ebay.sdk.util.*;
import org.apache.axis.types.Token;
import com.ebay.sdk.call.*;

/**
 * @author Zhuowei Yang
 */
public class AppAddItem {
    private String configFile= "request_header_param.properties";
    private ApiContext apiContext;
    /** Creates a new instance of AddItem */
   
    public AppAddItem() {
        RequestHeaderParam requestHeaderParam = new  RequestHeaderParam();
       
        apiContext = requestHeaderParam.createContext(configFile);
        apiContext.setErrorLanguage("en_US");
        apiContext.setSite(SiteCodeType.US);  
        //Enable logging
        ApiLogging logging = new ApiLogging();   
        apiContext.setApiLogging(logging);
    }
   
     public static void  main(String[] args){
        AppAddItem aai = new AppAddItem();
       
        try {
            ItemType item = aai.buildItem();
            FeesType fees;
            AddItemCall call = new AddItemCall(aai.apiContext);
            call.setItem(item);
            call.setAutoSetItemUUID(true);
            fees = call.addItem();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
   
    private ItemType buildItem() throws Exception{
        String title = "Test. Do not bid";
        ItemType item = new ItemType();

        item.setSite(SiteCodeType.US);
        item.setCurrency(CurrencyCodeType.USD);
        item.setTitle(title);
        item.setDescription("This is a test item created by eBay SDK.");
        item.setStartPrice(new AmountType(10.00));
        item.setListingDuration(new org.apache.axis.types.Token("Days_7"));
        item.setLocation("San Jose, CA");
        item.setCountry(CountryCodeType.US);
    
        CategoryType cat = new CategoryType();
        cat.setCategoryID("14111");
        item.setPrimaryCategory(cat);
       
        item.setQuantity(new Integer(1));
        // Payment method
        BuyerPaymentMethodCodeType[] arrPaymentMethods =
            new BuyerPaymentMethodCodeType[] {
            BuyerPaymentMethodCodeType.PaymentSeeDescription
        };
        item.setPaymentMethods(arrPaymentMethods);
        item.setShippingDetails(getShippingDetails());

        return item;
  }
    
   private ShippingDetailsType getShippingDetails(){
        
// construct shipping details container
        ShippingDetailsType sd = new ShippingDetailsType();
        sd.setShippingType(ShippingTypeCodeType.Flat);   
        ShippingServiceOptionsType st1 = new ShippingServiceOptionsType();
        st1.setShippingService(new org.apache.axis.types.Token("UPSGround"));
        st1.setShippingServiceAdditionalCost(new AmountType(2.0));
        st1.setShippingServiceCost(new AmountType(10));
        st1.setShippingServicePriority(new Integer(1));
        st1.setShippingInsuranceCost(new AmountType(1.0));
        sd.setShippingServiceOptions(new ShippingServiceOptionsType[]{st1});
       
        return sd;
    }

}


Version Info

The code example above was based on the versions specified below:

API Schema Version511 
Java SDK Versionjavasdk v511.0 Full release

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