Skip to main content
Published: August 19 2014, 9:32:00 AMUpdated: July 29 2022, 1:05:22 PM

Sample code in C# to list an Item with ShippingServices using .NET SDK

Summary

Prior to .NET SDK version 459, ShippingService was a code type and to list an item with a shipping service, you needed to use a value of the ShippingServiceCodeType enumeration.  Since SDK version 459,  it is a token, (essentially a string).  To set a value for the Shipping Service, you need to assign a valid string.  You can get a list of all the valid ShippingService values by making a call to GeteBayDetails.  If you are on a version prior to 459, it is strongly recommended that you update your SDK to the latest version.
 


 

Detailed Description

Here is a sample C# code using .NET SDK to list an item with Shipping Services:
 
/*
© 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.Title = 'title';
    item.Quantity = 1;
    item.PostalCode = '95125';
    item.ListingDuration = 'Days_7';
    item.PrimaryCategory = new CategoryType();
    item.PrimaryCategory.CategoryID = '146301';
    item.StartPrice = new AmountType();
    item.StartPrice.currencyID = CurrencyCodeType.USD;
    item.StartPrice.Value = 20;
    item.UUID = UUID;
         
    item.ShippingDetails = new ShippingDetailsType();
    item.ShippingDetails.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection();
    ShippingServiceOptionsType[] opt = new ShippingServiceOptionsType[2];
    opt[0] = new ShippingServiceOptionsType();    
    opt[0].ShippingServiceCost = new AmountType();
    opt[0].ShippingServiceCost.currencyID = CurrencyCodeType.USD;
    opt[0].ShippingServiceCost.Value = 5;
    // ShippingService is now a string
    //Make a call to GeteBayDetails to find out the valid Shipping Service values

    opt[0].ShippingService = 'USPSPriority';
    opt[0].ShippingServicePriority = 1;
    item.ShippingDetails.ShippingServiceOptions.Add(opt[0]);

    opt[1] = new ShippingServiceOptionsType();    
    opt[1].ShippingServiceCost = new AmountType();
    opt[1].ShippingServiceCost.currencyID = CurrencyCodeType.USD;
    opt[1].ShippingServiceCost.Value = 10;
    opt[1].ShippingService = 'USPSExpressMail';
    opt[1].ShippingServicePriority = 2;
    item.ShippingDetails.ShippingServiceOptions.Add(opt[1]);

    item.ShipToLocations = new StringCollection();
    item.ShipToLocations.Add('US');

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

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

  // Credentials for the call
  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 = '1131';

  return context;

    }

}

}

 


Additional Resources

 

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