Skip to main content
Published: March 17 2011, 7:50:00 AMUpdated: November 28 2020, 9:16:40 PM

 

Here is a sample written using the Java SDK for listing a fixed price item to the US site item using the AddFixedPriceItem call. This sample shows how to specify item specifics as name-value pairs for the listing.

 

/*
© 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 AppAddFixedPriceItemWithItemSpec {

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

        // set API Token to access eBay API Server
        ApiCredential cred = apiContext.getApiCredential();
        cred.seteBayToken(USER_TOKEN);
        apiContext.setApiCredential(cred);

        // set the site
        apiContext.setSite(SiteCodeType.US);

        return apiContext;
    }

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

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

        ItemType item = new ItemType();
        item.setTitle("Testing item. Dont bid");
        item.setDescription("Testing item. Dont bid");

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

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

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

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

        // 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.US);
        item.setCurrency(CurrencyCodeType.USD);
        CategoryType category = new CategoryType();
        category.setCategoryID("57990");
        item.setPrimaryCategory(category);
        item.setQuantity(10);

        item.setShippingDetails(getShippingDetails());

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

       // Add Item Specifics
        NameValueListArrayType itemSpec = new NameValueListArrayType();

        NameValueListType nv1 = new NameValueListType();
        nv1.setName("Brand");
        nv1.setValue(new String[]{"GAP"});
        
        NameValueListType nv2 = new NameValueListType();
        nv2.setName("Style");
        nv2.setValue(new String[]{"Button-Front"});

        NameValueListType nv3 = new NameValueListType();
        nv3.setName("Size Type");
        nv3.setValue(new String[]{"Regular"});

        NameValueListType nv4 = new NameValueListType();
        nv4.setName("Size (Men's)");
        nv4.setValue(new String[]{"M"});

        itemSpec.setNameValueList(new NameValueListType[]{nv1, nv2, nv3});

        item.setItemSpecifics(itemSpec);


        // 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("Return accepted");
        rp.setReturnsAcceptedOption("ReturnsAccepted");
        rp.setReturnsWithinOption("Days_30");
        return rp;
    }

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

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

        ShippingServiceOptionsType st2 = new ShippingServiceOptionsType();
        st2.setShippingService("USPSPriority");
        st2.setShippingServiceCost(getAmount(4));
        st2.setShippingServiceAdditionalCost(getAmount(1));

        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) {
            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