Skip to main content
Published: March 11 2010, 10:42:00 PMUpdated: November 28 2020, 8:17:06 PM

How to add local picture files to listing using Java SDK AddItemCall wrapper?

Detailed Description

  This sample illustrates the use of Java SDK AddItemCall wrapper to list an item that includes an image stored in local file system. The required steps are:

  1. Register EPS server URL in ApiContext object and  the String array object of the file name for the given images in AddItemCall object.

  2. Define the PictureDetail.GalleryTypeCodeType in ItemType object. 

/* *
* © 2010-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.AddItemCall;
import com.ebay.soap.eBLBaseComponents.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
*
* @author zhuyang
*/
public class AppAddItem {

    private ApiContext apiContext = new ApiContext();
    private static ApiLogging apiLogging = new ApiLogging();
    private static String[] pictureFiles = {"c:\\Sample.jpg"};
    String sandboxEPSURL = "https://api.sandbox.ebay.com/ws/api.dll";
    private static String TOKEN = "";
    private static String APISERVERURL = "https://api.sandbox.ebay.com/wsapi";
    public static final String DATE_FORMAT_NOW = "yyyy-MM-dd-HHmmss";

    public AppAddItem() {
        System.out.println(" current time : " + AppAddItem.now());
        ApiCredential cred = new ApiCredential();
        apiContext.setApiCredential(cred);
        //set api call credential
        apiContext.getApiCredential().seteBayToken(TOKEN);
        //enable api logging
        apiContext.setApiLogging(apiLogging);
        apiContext.setSite(SiteCodeType.US);
        apiContext.setApiServerUrl(APISERVERURL);
        //register EPS server URL in ApiContext object
        apiContext.setEpsServerUrl(sandboxEPSURL);
    }

    public static void main(String[] args) {
        AppAddItem agbb = new AppAddItem();
        ItemType item = agbb.buildItem(ListingTypeCodeType.FIXED_PRICE_ITEM);
        AddItemCall call = new AddItemCall(agbb.apiContext);
        call.setAutoSetItemUUID(true);
        //register the local picture files into AddItemCall object    
        call.setPictureFiles(pictureFiles);
        call.setItem(item);
        try {
            call.addItem();
            Thread.sleep(1000);
            System.out.println("Listed Item ID: " + item.getItemID());
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        } catch (Exception e) {
        }
    }

   
    private ItemType buildItem(ListingTypeCodeType listingType) {
        ItemType item = null;
        item = new ItemType();
        item.setListingType(listingType);
        item.setSite(SiteCodeType.US);
        item.setCurrency(CurrencyCodeType.USD);
        item.setCountry(CountryCodeType.US);
        item.setListingDuration("Days_7");
        item.setTitle("FIXED_PRICE_ITEM . Do not bid");
        item.setDescription("FIXED_PRICE_ITEM -  Do not bid");
        item.setLocation(" San Jose, CA");

        item.setQuantity(new Integer(1));
        // item.setScheduleTime(calAt);
        AmountType amount = new AmountType();
        amount.setValue(21.0);
        item.setStartPrice(amount);
        amount = new AmountType();
        amount.setValue(10.0);
        BuyerPaymentMethodCodeType[] paymentMethods = new BuyerPaymentMethodCodeType[]{
            BuyerPaymentMethodCodeType.PAY_PAL
        };

        item.setPaymentMethods(paymentMethods);
        item.setPayPalEmailAddress("ve2@testtest.com");
        CategoryType cat = new CategoryType();
        cat.setCategoryID("1463");
        item.setPrimaryCategory(cat);
        item.setDispatchTimeMax(new Integer(1));
        item.setShippingDetails(getShippingDetails());
        ReturnPolicyType rpt = new ReturnPolicyType();
        rpt.setReturnsAcceptedOption("ReturnsAccepted");

        rpt.setRefundOption("MoneyBack");
        rpt.setReturnsWithinOption("Days_30");
        rpt.setDescription("Text description of return policy details");
        rpt.setShippingCostPaidByOption("Buyer");
        item.setReturnPolicy(rpt);
        //define gallery picture type     
        PictureDetailsType pd = new PictureDetailsType();
        pd.setGalleryType(GalleryTypeCodeType.GALLERY);
        item.setPictureDetails(pd);

        return item;
    }

    private static ShippingDetailsType getShippingDetails() {
        // construct shipping details container
        ShippingDetailsType sd = new ShippingDetailsType();
        sd.setShippingType(ShippingTypeCodeType.FLAT);
        ShippingServiceOptionsType st1 = new ShippingServiceOptionsType();
        st1.setShippingService("UPSGround");
        AmountType amount = new AmountType();
        amount.setValue(10.0);
        st1.setShippingServiceCost(amount);
        st1.setShippingServicePriority(new Integer(1));
        sd.setShippingServiceOptions(new ShippingServiceOptionsType[]{st1});

        return sd;
    }

    public static String now() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        return sdf.format(cal.getTime());

    }
}

 


Version Info

The code example above was based on the versions specified below:

API Schema Version 639
Java SDK Version Java SDK v639 Full release

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