/*
© 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 AppAddFixedPriceItemWithMultiVariation {
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("95125");
item.setListingDuration("GTC");
// Track inventory by SKU
item.setInventoryTrackingMethod(InventoryTrackingMethodCodeType.SKU);
// Specify unique SKU
item.setSKU("VARPARENT");
// 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.setCountry(CountryCodeType.US);
item.setCurrency(CurrencyCodeType.USD);
CategoryType category = new CategoryType();
category.setCategoryID("57990");
item.setPrimaryCategory(category);
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, nv4});
item.setItemSpecifics(itemSpec);
// Specify VariationSpecificsSet
VariationsType vt = new VariationsType();
NameValueListType NVListVS1 = new NameValueListType();
NVListVS1.setName("Size");
String[] size = {"XS", "S", "M", "L", "XL"};
NVListVS1.setValue(size);
NameValueListType NVListVS2 = new NameValueListType();
NVListVS2.setName("Color");
String[] colour = {"Black", "Blue"};
NVListVS2.setValue(colour);
NameValueListArrayType nvla = new NameValueListArrayType();
nvla.setNameValueList(new NameValueListType[]{NVListVS1, NVListVS2});
VariationType v1 = new VariationType();
v1.setSKU("V1");
v1.setQuantity(new Integer(10));
v1.setStartPrice(getAmount(35));
NameValueListType Var1Spec1 = new NameValueListType();
Var1Spec1.setName("Color");
Var1Spec1.setValue(new String[]{"Black"});
NameValueListType Var1Spec2 = new NameValueListType();
Var1Spec2.setName("Size");
Var1Spec2.setValue(new String[]{"S"});
NameValueListArrayType nvla1 = new NameValueListArrayType();
nvla1.setNameValueList(new NameValueListType[]{Var1Spec1,Var1Spec2});
v1.setVariationSpecifics(nvla1);
VariationType v2 = new VariationType();
v2.setSKU("V2");
v2.setQuantity(new Integer(10));
v2.setStartPrice(getAmount(35));
NameValueListType Var2Spec1 = new NameValueListType();
Var2Spec1.setName("Color");
Var2Spec1.setValue(new String[]{"Black"});
NameValueListType Var2Spec2 = new NameValueListType();
Var2Spec2.setName("Size");
Var2Spec2.setValue(new String[]{"L"});
NameValueListArrayType nvla2 = new NameValueListArrayType();
nvla2.setNameValueList(new NameValueListType[]{Var2Spec1,Var2Spec2});
v2.setVariationSpecifics(nvla2);
VariationType v3 = new VariationType();
v3.setSKU("V3");
v3.setQuantity(new Integer(40));
v3.setStartPrice(getAmount(35));
NameValueListType Var3Spec1 = new NameValueListType();
Var3Spec1.setName("Color");
Var3Spec1.setValue(new String[]{"Blue"});
NameValueListType Var3Spec2 = new NameValueListType();
Var3Spec2.setName("Size");
Var3Spec2.setValue(new String[]{"M"});
NameValueListArrayType nvla3 = new NameValueListArrayType();
nvla3.setNameValueList(new NameValueListType[]{Var3Spec1,Var3Spec2});
v3.setVariationSpecifics(nvla3);
VariationType v4 = new VariationType();
v4.setSKU("V4");
v4.setQuantity(new Integer(10));
v4.setStartPrice(getAmount(35));
NameValueListType Var4Spec1 = new NameValueListType();
Var4Spec1.setName("Color");
Var4Spec1.setValue(new String[]{"Blue"});
NameValueListType Var4Spec2 = new NameValueListType();
Var4Spec2.setName("Size");
Var4Spec2.setValue(new String[]{"L"});
NameValueListArrayType nvla4 = new NameValueListArrayType();
nvla4.setNameValueList(new NameValueListType[]{Var4Spec1,Var4Spec2});
v4.setVariationSpecifics(nvla4);
PicturesType pic = new PicturesType();
pic.setVariationSpecificName("Color");
VariationSpecificPictureSetType vsp1 = new VariationSpecificPictureSetType();
vsp1.setPictureURL(new String[]{"http://i12.ebayimg.com/03/i/04/8a/5f/a1_1_sbl.JPG"});
vsp1.setVariationSpecificValue("Black");
VariationSpecificPictureSetType vsp2 = new VariationSpecificPictureSetType();
vsp2.setPictureURL(new String[]{"http://i2.sandbox.ebayimg.com/03/i/00/3f/c5/92_1.JPG?set_id=8800004005"});
vsp2.setVariationSpecificValue("Blue");
pic.setVariationSpecificPictureSet(new VariationSpecificPictureSetType[]{vsp1, vsp2});
vt.setVariationSpecificsSet(nvla);
vt.setVariation(new VariationType[]{v1, v2, v3, v4});
vt.setPictures(new PicturesType[]{pic});
item.setVariations(vt);
// Add item level 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("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(2));
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();
}
}
}
|