Skip to main content
Published: March 17 2011, 3:58:00 PMUpdated: November 28 2020, 9:18:00 PM

 

Here is a Java  SDK AddFixedPriceItem sample for listing an item with a product identifier (UPC).

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

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

public class AddFixedPriceItemWithProductIdentifier {

    private 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(120000);

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

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

        return apiContext;
    }

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

        FeesType fee = null;
        AddFixedPriceItemCall request = new AddFixedPriceItemCall(createApiContext());

        ItemType item = new ItemType();

        item.setTitle("*** TEST ITEM DO NOT BID ***");
        item.setDescription("Item created for testing. Please DO NOT BID");

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

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

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

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

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

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

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

        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("USPSPriority");

        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");
        rp.setReturnsWithinOption("Days_30");
        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.US);
        item.setCurrency(CurrencyCodeType.USD);
        item.setQuantity(10);

        // Adding product details (UPC)
        String UPC = "753759091033";   // (Electronics > GPS Navigation > GPS Systems)
        ProductListingDetailsType product = new ProductListingDetailsType();
        product.setUPC(UPC);

        // include catalog product information in the item description and catalog picture
        product.setIncludePrefilledItemInformation(true);
        product.setIncludeStockPhotoURL(true);

        item.setProductListingDetails(product);

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

        item.setPictureDetails(pics);

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

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

        return fee;
    }

    public static void main(String[] args) {

        try {
            FeesType fee = addWithUPC();
        } catch (ApiException e) {
            e.printStackTrace();
        } catch (SdkException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

}
 

The generated AddFixedPriceItem SOAP request is attached to this article.

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