Skip to main content
Published: August 19 2014, 9:27:00 AMUpdated: November 28 2020, 3:12:21 PM

Sample code in C# to list an Item with mixed shipping types using .NET SDK


Summary

With version 477, shipping supports a mix of flat and calculated shipping types on domestic and international shipping services.  The seller can opt to use flat shipping for domestic shipping services and calculated shipping for international shipping services, and vice versa by setting the ShippingType to FlatDomesticCalculatedInternational  and CalculatedDomesticFlatInternational respectively.


Detailed Description

Here is a sample C# code using .NET SDK to list an item with Shipping Services Flat Domestic and Calculated International shipping type:
 
/*
© 2007-2014 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/

using System;
using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Util;
using eBay.Service.Core.Soap;

namespace SDK3Examples
{

public class AddItem
{
public string AddItem(string UUID)
{
   AddItemCall addItem = new AddItemCall(GetContext());
    ItemType item = new ItemType();   
   
item.Currency = CurrencyCodeType.USD;
    item.Country = CountryCodeType.US;
    item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection();
    item.PaymentMethods.AddRange(new BuyerPaymentMethodCodeType[] {BuyerPaymentMethodCodeType.PayPal});
    item.PayPalEmailAddress = 'test@test.com';
    item.Title = 'title';
    item.Quantity = 1;
    item.PostalCode = '95125';
    item.ListingDuration = 'Days_7';
    item.PrimaryCategory = new CategoryType();
    item.PrimaryCategory.CategoryID = '12';
    item.StartPrice = new AmountType();
    item.StartPrice.currencyID = CurrencyCodeType.USD;
    item.StartPrice.Value = 20;
    item.UUID = UUID;
         
    item.ShippingDetails = new ShippingDetailsType();
    // Flat Domestic Calculated International Shipping Type
    item.ShippingDetails.ShippingType = ShippingTypeCodeType.FlatDomesticCalculatedInternational;

    // Domestic Shipping Services
    item.ShippingDetails.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection();
    ShippingServiceOptionsType[] opt = new ShippingServiceOptionsType[1];
    opt[0] = new ShippingServiceOptionsType();    
    opt[0].ShippingServiceCost = new AmountType();
    opt[0].ShippingServiceCost.currencyID = CurrencyCodeType.USD;
    opt[0].ShippingServiceCost.Value = 5;
    opt[0].ShippingService = 'USPSPriority';
    opt[0].ShippingServicePriority = 1;
    item.ShippingDetails.ShippingServiceOptions.Add(opt[0]);

    // Calculated Shipping values
    CalculatedShippingRateType calRate = new CalculatedShippingRateType();
    calRate.OriginatingPostalCode = '95125';
    calRate.ShippingPackage = ShippingPackageCodeType.PackageThickEnvelope;
    calRate.WeightMajor = new MeasureType();
    calRate.WeightMajor.unit = 'lbs';
    calRate.WeightMajor.Value = 2;
    calRate.WeightMinor = new MeasureType();
    calRate.WeightMinor.unit = 'oz';
    calRate.WeightMinor.Value = 6;
    item.ShippingDetails.CalculatedShippingRate = calRate;

    // International Shipping Services
    item.ShippingDetails.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection();
    InternationalShippingServiceOptionsType[] Iopt = new InternationalShippingServiceOptionsType[1];
    Iopt[0] = new InternationalShippingServiceOptionsType();
    Iopt[0].ShippingService = 'USPSGlobalExpress';
    Iopt[0].ShippingServicePriority = 1;
    item.ShippingDetails.InternationalShippingServiceOption.Add(Iopt[0]);
    Iopt[0].ShipToLocation = new StringCollection();
    Iopt[0].ShipToLocation.Add('Worldwide');

    FeeTypeCollection fees = addItem.AddItem(item);
    return  item.ItemID;
}

    public ApiContext GetContext()
    {
       ApiContext context = new ApiContext();

  // Credentials for the call
  context.ApiCredential.ApiAccount.Developer = 'devID';
  context.ApiCredential.ApiAccount.Application = 'appID';
  context.ApiCredential.ApiAccount.Certificate = 'certID';
  context.ApiCredential.eBayToken = 'token';

  // Set the URL
  context.SoapApiServerUrl = 'https://api.sandbox.ebay.com/wsapi'; 

  // Set logging
  context.ApiLogManager = newApiLogManager();
  context.ApiLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger('Messages.log', true, true, true));
  context.ApiLogManager.EnableLogging = true;

  // Set the version
  context.Version = '485';

  return context;

    }

}

}


Here is the corresponding SOAP Request:

<?xml version='1.0' encoding='utf-8'?>

<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>

  <soap:Header>

    <RequesterCredentials xmlns='urn:ebay:apis:eBLBaseComponents'>

      <ebl:eBayAuthToken xmlns:ebl='urn:ebay:apis:eBLBaseComponents'>*****</ebl:eBayAuthToken>

    </RequesterCredentials>

  </soap:Header>

  <soap:Body>

    <AddItemRequest xmlns='urn:ebay:apis:eBLBaseComponents'>

      <MessageID>e08e189d-c394-4650-8007-77132bed98df</MessageID>

      <Version>485</Version>

      <Item>

        <Country>US</Country>

        <Currency>USD</Currency>

        <Description>test description</Description>

        <ListingDuration>Days_7</ListingDuration>

        <PaymentMethods>PayPal</PaymentMethods>

        <PayPalEmailAddress>test@foo.com</PayPalEmailAddress>

        <PrimaryCategory>

          <CategoryID>12</CategoryID>

        </PrimaryCategory>

        <Quantity>1</Quantity>

        <ShippingDetails>

          <CalculatedShippingRate>

            <OriginatingPostalCode>95125</OriginatingPostalCode>

            <ShippingPackage>PackageThickEnvelope</ShippingPackage>

            <WeightMajor unit='lbs'>2</WeightMajor>

            <WeightMinor unit='oz'>6</WeightMinor>

          </CalculatedShippingRate>

          <ShippingServiceOptions>

            <ShippingService>USPSPriority</ShippingService>

            <ShippingServiceCost currencyID='USD'>5</ShippingServiceCost>

            <ShippingServicePriority>1</ShippingServicePriority>

          </ShippingServiceOptions>

          <InternationalShippingServiceOption>

            <ShippingService>USPSGlobalExpress</ShippingService>

            <ShippingServicePriority>1</ShippingServicePriority>

            <ShipToLocation>Worldwide</ShipToLocation>

          </InternationalShippingServiceOption>

          <ShippingType>FlatDomesticCalculatedInternational</ShippingType>

        </ShippingDetails>

        <StartPrice currencyID='USD'>20</StartPrice>

        <Title>Test - Do not bid</Title>

        <UUID>3f127adacb7d45d0999bca100fd9795b</UUID>

        <PostalCode>95125</PostalCode>

      </Item>

    </AddItemRequest>

  </soap:Body>

</soap:Envelope>

To flip this and set the domestic shipping type to calculated and international to flat:
1.  set item.ShippingDetails.ShippingType = ShippingTypeCodeType.FlatDomesticCalculatedInternational
2.   Remove the ShippingServiceCost for the domestic shipping services:
      opt[0].ShippingServiceCost = new AmountType();
      opt[0].ShippingServiceCost.currencyID = CurrencyCodeType.USD;
      opt[0].ShippingServiceCost.Value = 5;
3.  Add the ShippingServiceCost for the international shipping services:
      Iopt[0].ShippingServiceCost = new AmountType();
      Iopt[0].ShippingServiceCost.currencyID = CurrencyCodeType.USD;
      Iopt[0].ShippingServiceCost.Value = 5;


Version Info

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

API Schema Version 485
.NET SDK Version .NET SDK v485.0 full release



Additional Resources

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