Skip to main content
Published: July 27 2010, 8:54:00 PMUpdated: November 28 2020, 8:31:46 PM

Here is a basic sample written using the Java SDK (v811) for listing a fixed price item to the UK site using the AddFixedPriceItem call. The sample has been written in Java

Below is the code. Corresponding SOAP request is attached with this article.

/*  © 2010-2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 -  http://opensource.org/licenses/cddl1.php */

package com.ebay.sample;

import com.ebay.sdk.ApiAccount;
import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.ApiException;
import com.ebay.sdk.ApiLogging;
import com.ebay.sdk.CallRetry;
import com.ebay.sdk.SdkException;
import com.ebay.sdk.call.AddFixedPriceItemCall;
import com.ebay.soap.eBLBaseComponents.AmountType;
import com.ebay.soap.eBLBaseComponents.BuyerPaymentMethodCodeType;
import com.ebay.soap.eBLBaseComponents.CategoryType;
import com.ebay.soap.eBLBaseComponents.CountryCodeType;
import com.ebay.soap.eBLBaseComponents.CurrencyCodeType;
import com.ebay.soap.eBLBaseComponents.FeesType;
import com.ebay.soap.eBLBaseComponents.InventoryTrackingMethodCodeType;
import com.ebay.soap.eBLBaseComponents.ItemType;
import com.ebay.soap.eBLBaseComponents.PictureDetailsType;
import com.ebay.soap.eBLBaseComponents.ReturnPolicyType;
import com.ebay.soap.eBLBaseComponents.ShippingDetailsType;
import com.ebay.soap.eBLBaseComponents.ShippingServiceOptionsType;
import com.ebay.soap.eBLBaseComponents.SiteCodeType;

public class AppAddFixedPriceItem {

     public static String USER_TOKEN=" YOUR TOKEN";
     public static ApiContext createApiContext() {
          ApiContext apiContext = new ApiContext();
          ApiLogging apiLogging = new ApiLogging();
          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[] { "502" };
          // 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(180000);

          ApiCredential cred = new ApiCredential();

          // set the server url. Pointing to Sandbox
          apiContext.setApiServerUrl("https://api.sandbox.ebay.com/wsapi");

          cred.seteBayToken(USER_TOKEN);
          apiContext.setApiCredential(cred);
          return apiContext;
     }

     private static FeesType addFixedItem() throws ApiException, SdkException,
               Exception {

          FeesType fee = null;
          AddFixedPriceItemCall request = new AddFixedPriceItemCall(
                    createApiContext());
          request.setSite(SiteCodeType.UK);

          // Send UUID with the request
          request.setAutoSetItemUUID(true);

          ItemType item = new ItemType();
          item.setConditionID(1000);
          item.setTitle("Testing item. Dont bid");
          item.setDescription("Testing item. Dont bid");
          item.setSite(SiteCodeType.UK);

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

          item.setPostalCode("SE6 1AL");
          item.setListingDuration("Days_7");

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

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

          // Set Payment Method to PayPal
          BuyerPaymentMethodCodeType[] arrPaymentMethods = new BuyerPaymentMethodCodeType[] { BuyerPaymentMethodCodeType.PAY_PAL };
          item.setPayPalEmailAddress("test@pp.com");
          item.setPaymentMethods(arrPaymentMethods);

          // Specify Quantity, Start Price and the eBay category
          item.setStartPrice(getAmount(11.0));
          item.setCountry(CountryCodeType.GB);
          item.setCurrency(CurrencyCodeType.GBP);
          CategoryType category = new CategoryType();
          category.setCategoryID("122726");
          item.setPrimaryCategory(category);
          item.setQuantity(10);

          item.setShippingDetails(getShippingDetails());

          item.setDispatchTimeMax(2);
          item.setReturnPolicy(getReturnPolicy());

          // Add pictures
          PictureDetailsType pdt = new PictureDetailsType();
          pdt
                    .setPictureURL(new String[] { "http://i2.sandbox.ebayimg.com/03/i/00/3f/c5/92_1.JPG?set_id=8800004005" });

          request.setItem(item);
          fee = request.addFixedPriceItem();

          return fee;
     }

     private static ReturnPolicyType getReturnPolicy() {
          ReturnPolicyType rp = new ReturnPolicyType();
          rp.setDescription("No return accepted");
          rp.setReturnsAcceptedOption("ReturnsNotAccepted");
          return rp;
     }

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

          ShippingServiceOptionsType st1 = new ShippingServiceOptionsType();
          st1.setShippingService("UK_SellersStandardRate");
          st1.setShippingServiceCost(getAmount(1));
          st1.setShippingServiceAdditionalCost(getAmount(1));

          ShippingServiceOptionsType st2 = new ShippingServiceOptionsType();
          st2.setShippingService("UK_RoyalMailFirstClassStandard");
          st2.setShippingServiceCost(getAmount(4));

          sd.setShippingServiceOptions(new ShippingServiceOptionsType[] { st1,
                    st2 });

          return sd;
     }

     private static AmountType getAmount(double amount) {
          AmountType a = new AmountType();
          a.setValue(amount);
          return a;
     }

     public static void main(String[] args) {

          try {
               FeesType fee = addFixedItem();
          } catch (ApiException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (SdkException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (Exception e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          }

     }
}
     

 

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