question

tevesus avatar image
0 Likes"
tevesus asked

Using Ebay SDK API: ExcludeShipToLocation.Add("CN") causes:“Object reference not set to an instance of an object”

I've been trying to figure out how to exclude some locations using Ebay API Csharp but so far I haven't solved this after so many code variations and deep-googling. I need help in excluding "China" item.ShippingDetails.ExcludeShipToLocation = new StringCollection(); But when the program hits this ^ line of code, this error shows up: "Object reference not set to an instance of an object" If you would like to see the full code here it is: using eBay.Service.Call; using eBay.Service.Core.Sdk; using eBay.Service.Core.Soap; using eBay.Service.Util; using Samples.Helper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ebayapiex3 { class Program { static void Main(string[] args) { ApiContext context = AppSettingHelper.GetApiContext(); context.ApiLogManager = new ApiLogManager(); context.ApiLogManager.ApiLoggerList.Add(new FileLogger(" log.txt", true, true, true)); context.ApiLogManager.EnableLogging = true; context.Site = SiteCodeType.US; ReviseFixedPriceItemCall reviseFP = new ReviseFixedPriceItemCall(context); ItemType item = new ItemType(); item.ItemID = "************"; item.Title = "TITLE HAS BEEN CHANGED"; item.Quantity = 99; item.StartPrice = new AmountType(); item.StartPrice.Value = 795.76; item.ShipToLocations = new StringCollection(); item.ShipToLocations.Add("US"); item.ShipToLocations.Add("AU"); item.ShippingDetails.ExcludeShipToLocation = new StringCollection(); item.ShippingDetails.ExcludeShipToLocation.Add("CN"); reviseFP.Item = item; reviseFP.Execute(); Console.WriteLine(reviseFP.ApiResponse.Ack + " SKU " + reviseFP.SKU); } } }
c# ebay api object error
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
jourbandts avatar image
0 Likes"
jourbandts answered
It looks like you have not created a ShippingDetails container yet. Try to add the following, item.ShippingDetails = new ShippingDetailsType(); Here is a C# example that shows how to set up shipping, https://ebaydts.com/eBayKBDetails?KBid=1622, even though there is not an exclusion list. But your 2 lines of code for the exclusion list look good. You just need the ShippingDetailsType set up first.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.