0

My goal here so to make the listing say "Free International Shipping". Trying to set up international options and it said I need to set ShipToLocation I tried the line below:

internationalShippingOptions.ShipToLocation.Add("Worldwide");

But when the program hits it I get this error:

"Object reference not set to an instance of an object"

If you would like to see the full method it is:

    static ShippingDetailsType BuildShippingDetails()
    {

        ShippingDetailsType sd = new ShippingDetailsType();
        sd.ApplyShippingDiscount = false;
        sd.ShippingType = ShippingTypeCodeType.Flat;

        AmountType amount = new AmountType();
        amount.Value = 0;
        amount.currencyID = CurrencyCodeType.USD;            

        ShippingServiceOptionsTypeCollection shippingOptions = new ShippingServiceOptionsTypeCollection();

        ShippingServiceOptionsType domesticShippingOptions = new ShippingServiceOptionsType();
        domesticShippingOptions.ShippingService = ShippingServiceCodeType.EconomyShippingFromOutsideUS.ToString();
        domesticShippingOptions.FreeShipping = true;
        domesticShippingOptions.ShippingServiceCost = amount;
        domesticShippingOptions.ShippingServicePriority = 1;
        shippingOptions.Add(domesticShippingOptions);

        ShippingServiceOptionsType internationalShippingOptions = new ShippingServiceOptionsType();
        InternationalShippingServiceOptionsType internationalShippingOptions = new InternationalShippingServiceOptionsType();
        internationalShippingOptions.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
        internationalShippingOptions.ShipToLocation.Add("Worldwide");
        internationalShippingOptions.FreeShipping = true;

        sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new InternationalShippingServiceOptionsType[] { internationalShippingOptions });
        sd.ShippingServiceOptions = shippingOptions;

        return sd;
    }
Cray
  • 2,347
  • 7
  • 17
  • 27
Danny
  • 808
  • 1
  • 8
  • 15
  • I think you copied the wrong line as your error message. You should also mention that you are working with the ebay sdk. It took me a while until I saw that in the tags. – Wutz May 16 '13 at 12:59
  • Hard to tell what is wrong when you do not supply a proper error message. Perhaps you haven't created a `new ShipToLocation()` and this results in a NullPointer? – McIntosh May 16 '13 at 13:58
  • haha, yeah how did that happen. I fixed it now, thanks for reading – Danny May 16 '13 at 14:57
  • I don't know the ebay sdk, but it looks like `ShipToLocation` is null. Try `internationalShippingOptions.ShipToLocation = new ...()` (replace the `...` with the type of the `ShipToLocation` property) before you call `Add`. If that does not work check the documentation, maybe you will find an example on how to use this. – Wutz May 16 '13 at 15:17
  • Thank you Wutz, I'm having trouble figuring this out. I'm sure you are on the right track, I just don't know how to do the syntax and I cant find an example anywhere. I have this information but I still cant figure it out, would someone be able to give me an example?........ Use GeteBayDetails with DetailName set to ShippingLocationDetails to determine which locations are valid per site. In the GeteBayDetails response, look for the ShippingLocationDetails.ShippingLocation fields. For the AddItem family of calls, this field is required if any international shipping service is specified. – Danny May 16 '13 at 17:15
  • Actually I did find an example here.....https://ebay.custhelp.com/app/answers/detail/a_id/860...They did it like this: tem.ShipToLocations = new StringCollection(); item.ShipToLocations.Add("US"); But when I tried this I still get the same error message: "Fail to list the item: Your application encountered an error. This request is missing required value in input tag .." So I suppose it didn't work or maybe I'm on the wrong track and it is another problem? – Danny May 16 '13 at 18:09
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Stephen Kennedy Feb 27 '18 at 09:31

1 Answers1

0

Here is the code to make it say "Free Standard Intl Shipping". At first in the sandbox it says "Free Standard Shipping" but if you change the shipping destination in the sandbox it will say "Free Standard Intl Shipping".

    static ShippingDetailsType BuildShippingDetails()
    {
        // Shipping details
        ShippingDetailsType sd = new ShippingDetailsType();

        sd.ApplyShippingDiscount = true;
        sd.PaymentInstructions = "eBay .Net SDK test instruction.";
        sd.ShippingRateType = ShippingRateTypeCodeType.StandardList;

        // Shipping type and shipping service options
        //adding international shipping
        InternationalShippingServiceOptionsType internationalShipping1 = new InternationalShippingServiceOptionsType();
        internationalShipping1.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
        internationalShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        internationalShipping1.ShippingServicePriority = 1;
        internationalShipping1.ShipToLocation = new StringCollection(new[] { "Worldwide" });
        sd.ShippingServiceUsed = ShippingServiceCodeType.StandardInternational.ToString();
        sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new[] { internationalShipping1 });

        //adding domestic shipping
        ShippingServiceOptionsType domesticShipping1 = new ShippingServiceOptionsType();
        domesticShipping1.ShippingService = ShippingServiceCodeType.ShippingMethodStandard.ToString();
        domesticShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        domesticShipping1.ShippingInsuranceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        domesticShipping1.ShippingServicePriority = 4;
        domesticShipping1.LocalPickup = true;
        domesticShipping1.FreeShipping = true;
        sd.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(new[] { domesticShipping1 });
        sd.ShippingType = ShippingTypeCodeType.Flat;

        return sd;

To call the method:

 item.ShippingDetails = BuildShippingDetails();
Danny
  • 808
  • 1
  • 8
  • 15