public bool NewListing(bool live, string upc, double price, string[] picFiles, string titleOverride, string description, Shipping shipping, EbayCategory ebayCategory, out string response, out string id, bool forceTitleOverride = false, int lbs = 0, int oz = 0) { ApiContext apiContext = GetApiContext(live); bool useTitleOverride = forceTitleOverride; { var addItem = new VerifyAddFixedPriceItemCall(apiContext) { Item = CreateItem(upc, price, titleOverride, description, shipping, ebayCategory, useTitleOverride, lbs, oz), PictureFileList = new StringCollection(picFiles), }; try { addItem.Execute(); } catch (Exception ex) { useTitleOverride = true; } } { var addItem = new AddFixedPriceItemCall(apiContext) { Item = CreateItem(upc, price, titleOverride, description, shipping, ebayCategory, useTitleOverride, lbs, oz), PictureFileList = new StringCollection(picFiles), }; try { addItem.Execute(); } catch (Exception ex) { id = "-1"; response = ex.ToString(); return false; } response = "OK!"; id = addItem.ApiResponse.ItemID; } return true; }
private ItemType CreateItem(string upc, double price, string titleOverride, string description, Shipping shipping, EbayCategory ebayCategory, bool forceTitleOverride, int lbs, int oz) { var item = new ItemType(); item.PictureDetails = new PictureDetailsType(); item.PictureDetails.GalleryType = GalleryTypeCodeType.Gallery; item.BestOfferDetails = new BestOfferDetailsType { BestOfferEnabled = true }; item.IncludeRecommendations = true; item.Title = forceTitleOverride ? titleOverride : ""; ; item.Description = description; switch (ebayCategory) { case EbayCategory.Console: item.PrimaryCategory = new CategoryType() { CategoryID = "48752" }; item.ConditionID = 3000; break; case EbayCategory.Game: item.PrimaryCategory = new CategoryType() { CategoryID = "139973" }; item.ConditionID = 4000; break; } item.ProductListingDetails = new ProductListingDetailsType { UPC = upc }; item.StartPrice = new AmountType() { currencyID = CurrencyCodeType.USD, Value = price }; item.Currency = CurrencyCodeType.USD; item.Country = CountryCodeType.US; item.DispatchTimeMax = 1; item.ListingDuration = "Days_30"; item.ListingType = ListingTypeCodeType.FixedPriceItem; item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection { BuyerPaymentMethodCodeType.PayPal }; item.PayPalEmailAddress = paypalEmail; item.PostalCode = locationZip.ToString(); item.Quantity = 1; item.ReturnPolicy = new ReturnPolicyType() { ReturnsAcceptedOption = "ReturnsAccepted", RefundOption = "MoneyBack", ReturnsWithinOption = "Days_14", ShippingCostPaidByOption = "Buyer" }; string shippingMethod = ""; decimal shippingLbs = 0; decimal shippingOz = 0; switch (shipping) { case Shipping.FirstClass: shippingMethod = "USPSFirstClass"; if (oz == 0) { shippingOz = 5; } else { shippingOz = (decimal)oz; } break; case Shipping.PriorityByWeight: shippingMethod = "USPSPriority"; if (lbs == 0) { shippingLbs = 2; } else { shippingLbs = (decimal)lbs; shippingOz = (decimal)oz; } break; case Shipping.SmallFlatRate: shippingMethod = "USPSPriorityMailSmallFlatRateBox"; shippingLbs = 5; break; case Shipping.MediumFlatRate: shippingMethod = "USPSPriorityMailFlatRateBox"; shippingLbs = 10; break; case Shipping.LargeFlatRate: shippingMethod = "USPSPriorityMailLargeFlatRateBox"; shippingLbs = 15; break; default: break; } item.ShippingDetails = new ShippingDetailsType { ShippingType = ShippingTypeCodeType.Calculated, CalculatedShippingRate = new CalculatedShippingRateType { OriginatingPostalCode = locationZip.ToString(), PackagingHandlingCosts = new AmountType { currencyID = CurrencyCodeType.USD, Value = 0.0 }, ShippingPackage = ShippingPackageCodeType.PackageThickEnvelope, WeightMajor = new MeasureType { measurementSystem = MeasurementSystemCodeType.English, unit = "lbs", Value = shippingLbs }, WeightMinor = new MeasureType { measurementSystem = MeasurementSystemCodeType.English, unit = "oz", Value = shippingOz } }, ShippingServiceOptions = new ShippingServiceOptionsTypeCollection{ new ShippingServiceOptionsType{ ShippingService = shippingMethod, ShippingServicePriority = 1, } } }; return item; }