Skip to main content
Published: August 07 2006, 8:22:00 AMUpdated: November 28 2020, 2:20:31 PM

How to Add Item with Shipping options in JAVA SDK?

How to AddItem with Shipping options in JAVA SDK?

1. First, you need to find out the available shipping services and shipping locations for the given site, this can be accomplished with GeteBayDetails api call. Below is the main method of getting ShippingServiceDetails and ShippingLocationDetail for eBay US site:

AppGeteBayDetails.java
======================

public static void  main(String[] args){
        AppGeteBayDetails agbd = new AppGeteBayDetails();    
        try {
            agbd.apiContext.setSite(SiteCodeType.US);
            //agbd.apiContext.setSite(SiteCodeType.Australia);
            GeteBayDetailsCall request = new GeteBayDetailsCall(agbd.apiContext);
            request.setDetailName(new DetailNameCodeType[]{
                      DetailNameCodeType.ShippingServiceDetails,
                      DetailNameCodeType.ShippingLocationDetails
            });
            request.geteBayDetails(); 
            GeteBayDetailsResponseType resp = request.getReturnedeBayDetails();
            ShippingServiceDetailsType[] shippingServiceArray = resp.getShippingServiceDetails();
            for (int i=0; i<shippingServiceArray.length; i++){
                ShippingServiceDetailsType shippingService = shippingServiceArray[i];
                shippingService.getShippingService();
                shippingService.getDescription();
            }
           
            ShippingLocationDetailsType[] ShippingLocationArray =  resp.getShippingLocationDetails();
            for (int j=0; j<ShippingLocationArray.length; j++){
                ShippingLocationDetailsType shippingLocation = ShippingLocationArray[j];
                shippingLocation.getShippingLocation();
                shippingLocation.getDescription();
            }
           
        }catch(Exception e){
            e.printStackTrace();
        }
    }
   
    Here is the GeteBayDetailsRequest xml log generated from the code above:
    Sending SOAP request to: https://api.sandbox.ebay.com/wsapi?siteid=0&callname=GeteBayDetails&client=java
    - HTTP Compression: send gzip request...
    - HTTP Compression - gzip decompress response: ContentLength=905
    - Request Message: Length=1,670
    - <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <soapenv:Header>
      <ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
       <ebl:eBayAuthToken xmlns:ebl="urn:ebay:apis:eBLBaseComponents">YOUR TOKEN</ebl:eBayAuthToken>
      </ebl:RequesterCredentials>
     </soapenv:Header>
     <soapenv:Body>
      <GeteBayDetailsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
       <ErrorLanguage>en_US</ErrorLanguage>
       <Version>463</Version>
       <DetailName>ShippingServiceDetails</DetailName>
       <DetailName>ShippingLocationDetails</DetailName>
      </GeteBayDetailsRequest>
     </soapenv:Body>
    </soapenv:Envelope>

  
2. You can either save the shipping information to your local repository or to memory.

3. Third, you need to create ShippingServiceOptionsType object and build ItemType object, and then pass the objects to AddItem request. The code sample is as below:

   AddItemReqSample.java
   =====================
  
   public static void  main(String[] args){
        
       AddItemReqSample sample = new AddItemReqSample ();
     
       try{
            ItemType item = sample.buildItem();
            FeesType fees;
            VerifyAddItemCall request= new VerifyAddItemCall(sample.apiContext);
            fees = request.addItem(item);
                  
         }catch(Exception e){
             e.printStackTrace();
         }
     }
    
     private ItemType buildItem(){
         String str = "eBay Test. DO NOT BID!";
         ItemType item = new ItemType();
 
         item.setSite(SiteCodeType.US);
         item.setCurrency(CurrencyCodeType.USD);
         item.setListingType(ListingTypeCodeType.Chinese);    
         item.setTitle(str);
         item.setDescription("This is a test item created by eBay SDK Test.");
         item.setStartPrice(new AmountType(0.01));
         item.setListingDuration(ListingDurationCodeType.Days_7.getValue());
         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
         BuyerPaymentMethodCodeType[] arrPaymentMethods =
             new BuyerPaymentMethodCodeType[] {BuyerPaymentMethodCodeType.PaymentSeeDescription};
         item.setPaymentMethods(arrPaymentMethods);
 
         // Shipping range
         item.setShippingOption(ShippingOptionCodeType.WorldWide);
         //
         item.setShippingDetails(getShippingDetails());
         return item;
   }
     
   private ShippingDetailsType getShippingDetails(){
        
         sd.setShippingType(ShippingTypeCodeType.Flat);
 
         ShippingServiceOptionsType st1 = new ShippingServiceOptionsType();
         st1.setShippingService(ShippingServiceCodeType.USPSPriority.getValue());
         st1.setShippingServiceAdditionalCost(new AmountType(2.0));
         st1.setShippingServiceCost(new AmountType(10));
         st1.setShippingServicePriority(new Integer(1));
         st1.setShippingInsuranceCost(new AmountType(1.0));
 
         ShippingServiceOptionsType st2 = new ShippingServiceOptionsType();
         st2.setExpeditedService(new Boolean(true));
         st2.setShippingService(ShippingServiceCodeType.USPSFirstClass.getValue());
         st2.setShippingServiceAdditionalCost(new AmountType(2.0));
         st2.setShippingServiceCost(new AmountType(15));
         st2.setShippingServicePriority(new Integer(2));
         st2.setShippingInsuranceCost(new AmountType(1.0));
 
         sd.setShippingServiceOptions(new ShippingServiceOptionsType[]{st1, st2});
 
         return sd;
    }
   
 Here is the AddItemRequest xml log generated from the above AddItemReqSample java code:
 
 - Sending SOAP request to: https://api.sandbox.ebay.com/wsapi?siteid=0&callname=AddItem&client=java
 - HTTP Compression: send gzip request...
 - HTTP Compression - gzip decompress response: ContentLength=641
 - Request Message: Length=3,477
 - <?xml version="1.0" encoding="UTF-8"?>
 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
   <ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
    <ebl:eBayAuthToken xmlns:ebl="urn:ebay:apis:eBLBaseComponents">YOUR TOKEN</ebl:eBayAuthToken>
   </ebl:RequesterCredentials>
  </soapenv:Header>
  <soapenv:Body>
   <AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
    <ErrorLanguage>en_US</ErrorLanguage>
    <Version>463</Version>
    <Item>
     <Country>US</Country>
     <Currency>USD</Currency>
     <Description>This is a test item created by eBay SDK Test.</Description>
     <ListingDuration>Days_7</ListingDuration>
     <ListingType>Chinese</ListingType>
     <Location>San Jose, CA</Location>
     <PaymentMethods>PaymentSeeDescription</PaymentMethods>
     <PrimaryCategory>
      <CategoryID>14111</CategoryID>
     </PrimaryCategory>
     <Quantity>1</Quantity>
     <ShippingOption>WorldWide</ShippingOption>
     <ShippingDetails>
      <AllowPaymentEdit>false</AllowPaymentEdit>
      <ApplyShippingDiscount>true</ApplyShippingDiscount>
      <InsuranceFee>2.8</InsuranceFee>
      <InsuranceOption>Optional</InsuranceOption>
      <PaymentInstructions>eBay Java SDK test instruction.</PaymentInstructions>
      <SalesTax>
       <SalesTaxPercent>0.0825</SalesTaxPercent>
       <SalesTaxState>CA</SalesTaxState>
      </SalesTax>
      <SellerPostalCode>94087</SellerPostalCode>
      <ShippingServiceOptions>
       <ShippingInsuranceCost>1.0</ShippingInsuranceCost>
       <ShippingService>USPSPriority</ShippingService>
       <ShippingServiceCost>10.0</ShippingServiceCost>
       <ShippingServiceAdditionalCost>2.0</ShippingServiceAdditionalCost>
       <ShippingServicePriority>1</ShippingServicePriority>
      </ShippingServiceOptions>
      <ShippingServiceOptions>
       <ShippingInsuranceCost>1.0</ShippingInsuranceCost>
       <ShippingService>USPSFirstClass</ShippingService>
       <ShippingServiceCost>15.0</ShippingServiceCost>
       <ShippingServiceAdditionalCost>2.0</ShippingServiceAdditionalCost>
       <ShippingServicePriority>2</ShippingServicePriority>
       <ExpeditedService>true</ExpeditedService>
      </ShippingServiceOptions>
      <ShippingType>Flat</ShippingType>
     </ShippingDetails>
     <Site>US</Site>
     <StartPrice>0.01</StartPrice>
     <Title>eBay SDK Test. DO NOT BID!</Title>
    </Item>
   </AddItemRequest>
  </soapenv:Body>
 </soapenv:Envelope>

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