Skip to main content
Published: October 04 2010, 5:39:00 AMUpdated: November 28 2020, 9:00:18 PM

If you list an item with product data, your item has better chances of being surfaced in the search results. Here is a Java AddFixedPriceItem sample for listing an item with product identifier. Both UPC and MPN are passed in the request and eBay uses the first matching product to prefill the item listing.

This sample has been written using the Java SDK v811

References:

Listing with Product Data

Finding ePID

 

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.ApiContext;
import com.ebay.sdk.ApiCredential;
import com.ebay.sdk.ApiException;
import com.ebay.sdk.SdkException;
import com.ebay.sdk.call.AddFixedPriceItemCall;
import com.ebay.soap.eBLBaseComponents.AmountType;
import com.ebay.soap.eBLBaseComponents.BrandMPNType;
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.GalleryTypeCodeType;
import com.ebay.soap.eBLBaseComponents.InventoryTrackingMethodCodeType;
import com.ebay.soap.eBLBaseComponents.ItemType;
import com.ebay.soap.eBLBaseComponents.PictureDetailsType;
import com.ebay.soap.eBLBaseComponents.ProductListingDetailsType;
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 AddFixedPriceItemWithEPID {
     

     private static String USER_TOKEN="YOUR TOKEN";
     public static void addWithEPID() {
          ApiContext apiContext = new ApiContext();
          // set API Token to access eBay API Server
          ApiCredential cred = apiContext.getApiCredential(); 
          cred.seteBayToken(USER_TOKEN); 

          // Pointing to sandbox for testing.
          apiContext.setApiServerUrl("https://api.sandbox.ebay.com/wsapi");
          // This will log SOAP requests and responses.
          apiContext.getApiLogging().setLogSOAPMessages(true);

          apiContext.setSite(SiteCodeType.UK); // Set site to UK

          AddFixedPriceItemCall request = new AddFixedPriceItemCall(apiContext);
          request.setSite(SiteCodeType.UK);

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

          ItemType item = new ItemType();
          item.setConditionID(1000);
          item.setTitle("*** TEST ITEM DO NOT BID ***");
          item.setDescription("Item created for testing. Please DO NOT 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("ADDFP_PID_TEST_GARMIN_002");

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

          // Set Category
          CategoryType category = new CategoryType();
          category.setCategoryID("156955");

          item.setPrimaryCategory(category);

          // Set shipping services
          ShippingDetailsType sd = new ShippingDetailsType();

          ShippingServiceOptionsType st1 = new ShippingServiceOptionsType();
          st1.setShippingService("UK_SellersStandardRate");

          AmountType shipAmt1 = new AmountType();
          shipAmt1.setValue(4.0);

          st1.setShippingServiceCost(shipAmt1);

          AmountType shipAmt1Addnl = new AmountType();
          shipAmt1Addnl.setValue(2.0);

          st1.setShippingServiceAdditionalCost(shipAmt1Addnl);

          ShippingServiceOptionsType st2 = new ShippingServiceOptionsType();
          st2.setShippingService("UK_RoyalMailFirstClassStandard");

          AmountType shipAmt2 = new AmountType();
          shipAmt2.setValue(2.0);

          st2.setShippingServiceCost(shipAmt2);

          AmountType shipAmt2Addnl = new AmountType();
          shipAmt2Addnl.setValue(2.0);

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

          item.setShippingDetails(sd); // Add shipping details

          // Specify return policy
          ReturnPolicyType rp = new ReturnPolicyType();
          rp.setDescription("Return accepted (Conditions apply)");
          rp.setReturnsAcceptedOption("ReturnsAccepted");

          item.setReturnPolicy(rp); // Add return policy to the item

          // Specify Quantity, Start Price
          AmountType amt = new AmountType();
          amt.setValue(1.0);
          item.setStartPrice(amt);
          item.setCountry(CountryCodeType.GB);
          item.setCurrency(CurrencyCodeType.GBP);
          item.setQuantity(10);

          // Adding product details (BRAND MPN, UPC)
          String UPC = "753759090913"; // Garmin nuvi 1350 GPS
          String Brand = "Garmin";
          String MPN = "010-00782-20";

          ProductListingDetailsType product = new ProductListingDetailsType();
          BrandMPNType brandMPN = new BrandMPNType();
          brandMPN.setMPN(MPN);
          brandMPN.setBrand(Brand);
          product.setBrandMPN(brandMPN);

          product.setIncludePrefilledItemInformation(true);

          // Include the eBay stock photo with the listing if available and use it
          // as the gallery picture
          product.setIncludeStockPhotoURL(true);
          product.setUseStockPhotoURLAsGallery(true);

          // If multiple product matches found, list the item with the 1st
          // product's information
          product.setUseFirstProduct(true);
          product.setListIfNoProduct(true);

          item.setProductListingDetails(product);

          PictureDetailsType pics = new PictureDetailsType();
          pics.setGalleryType(GalleryTypeCodeType.NONE);

          item.setPictureDetails(pics);

          item.setDispatchTimeMax(1); // Set handling time

          request.setItem(item);

          try {
               request.addFixedPriceItem();
          } catch (ApiException e) {
               e.printStackTrace();
          } catch (SdkException e) {
               e.printStackTrace();
          } catch (Exception e) {
               e.printStackTrace();
          }
     }

     public static void main(String[] args) {
          addWithEPID();
     }

}

 

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