Skip to main content
Published: December 04 2014, 8:24:00 AMUpdated: August 31 2022, 11:57:37 PM

 

The code sample was created by giving a WSDL web reference to Business Policies Management WSDL 
https://developer.ebay.com/devzone/business-policies/Concepts/BusinessPoliciesAPIGuide.html
 
Add a web service reference to the eBay Business Policies Management WSDL (Please use the latest version of the WSDL)
https://developer.ebay.com/devzone/business-policies/Concepts/BusinessPoliciesAPIGuide.html
 
 
Create a custom service by overriding the GetWebRequest method
 

CustomBusinessPoliciesManagement.cs

using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using BusinessPoliciesManagement_API_Sample.com.ebay.developer;

 

namespace BusinessPoliciesManagement_API_Sample

{

    public class CustomBusinessPoliciesManagement: SellerProfilesManagementService

    {

        protected override WebRequest GetWebRequest(Uri uri)

        {

            try

            {

                HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);

                request.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "getSellerProfiles");

                request.Headers.Add("X-EBAY-SOA-SECURITY-TOKEN", "YOUR-TOKEN-HERE");

                request.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");

                return request;

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

    }

}

 

 

 
Call the custom service and make the addSellerProfile API as follows to create Shipping Profile
 

Program.cs

using System;

using System.Collections.Generic;

using System.Text;

using BusinessPoliciesManagement_API_Sample.com.ebay.developer;

 

namespace BusinessPoliciesManagement_API_Sample

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                CustomBusinessPoliciesManagement service = new CustomBusinessPoliciesManagement();

                service.Url = @"http://svcs.sandbox.ebay.com/services/selling/v1/SellerProfilesManagementService";

 

                SetSellerProfileRequest request = new SetSellerProfileRequest();

                ShippingPolicyProfile shipProfile = new ShippingPolicyProfile();

                shipProfile.profileIdSpecified = true;

                shipProfile.profileId = 5153133000;

                shipProfile.profileName = "UPSGroundShippingOnly";

                shipProfile.profileType = ProfileType.SHIPPING;

                shipProfile.profileDesc = "Shipping policy created through API - Test description ";

                // Category Group

                CategoryGroup category = new CategoryGroup();

                category.@default = true;

                category.name = "ALL";

                CategoryGroup[] categoryArray = { category };

                shipProfile.categoryGroups = categoryArray;

 

                // Shipping Policy Info container

                ShippingPolicyInfo shipPolicyInfo = new ShippingPolicyInfo();

                shipPolicyInfo.dispatchTimeMaxSpecified = true;

                shipPolicyInfo.dispatchTimeMax = 3;

                shipPolicyInfo.domesticShippingType = "Flat";

                shipPolicyInfo.intlShippingType = "Flat";

                shipPolicyInfo.shippingPolicyCurrency = IsoCurrencyCode.USD;

 

                // Domestic Shipping

                ShippingPolicyInfoService domesticService = new ShippingPolicyInfoService();

                domesticService.shippingService = "USPSPriority";

                domesticService.shippingServiceCost = new Amount();

                domesticService.shippingServiceCost.Value = 20.00;

                domesticService.shippingServiceAdditionalCost = new Amount();

                domesticService.shippingServiceAdditionalCost.Value = 15.50;

                domesticService.sortOrderIdSpecified = true;

                domesticService.sortOrderId = 1;

                ShippingPolicyInfoService[] domesticShipping = { domesticService };

                shipPolicyInfo.domesticShippingPolicyInfoService = domesticShipping;

 

                // International Shipping

                ShippingPolicyInfoService intlService = new ShippingPolicyInfoService();

                intlService.shippingService = "USPSPriorityMailInternational";

                intlService.shippingServiceCost = new Amount();

                intlService.shippingServiceCost.Value = 30.00;

                intlService.shippingServiceAdditionalCost = new Amount();

                intlService.shippingServiceAdditionalCost.Value = 25.50;

                intlService.sortOrderIdSpecified = true;

                intlService.sortOrderId = 1;

                string[] shipToLocs = { "WorldWide" };

                intlService.shipToLocation = shipToLocs;

                ShippingPolicyInfoService[] intlShipping = { intlService };

                shipPolicyInfo.intlShippingPolicyInfoService = intlShipping;

 

                // Adding to Shipping Profile object

                shipProfile.shippingPolicyInfo = shipPolicyInfo;

                request.shippingPolicyProfile = shipProfile;

 

                SetSellerProfileResponse response = new SetSellerProfileResponse();

                response = service.setSellerProfile(request);

 

                if (response.ack == AckValue.Success)

                {

                    Console.WriteLine("Ack: " + response.ack.ToString());

                    Console.WriteLine("Shipping Profile Details:");

                    Console.WriteLine("Profile Name: " + response.shippingPolicyProfile.profileId);

                    Console.WriteLine("Profile ID: " + response.shippingPolicyProfile.profileName);

                }

                else

                {

                    foreach (ErrorData error in response.errorMessage)

                    {

                        Console.WriteLine("Error ID: " + error.errorId);

                        Console.WriteLine("Error Message: " + error.message);

                    }

                }

 

            }

            catch (Exception ex)

            {

                throw ex;

            }

            Console.ReadLine();

        }

 

       

 

    }

}

 

 

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

Got thoughts? Click the feedback button – your insights help us improve!