Last updated

Product Integration Examples

.NET code samples for importing product, on hand, and price data via the Norce Commerce Connect C# client library.

For integration patterns and field reference, see Product Import Guide and Working with the X-Stormconnect Header.


ImportProducts

View .NET code sample
// Using Storm Client library: https://github.com/StormCommerce/Storm.Connect.Contracts
// NuGet: https://www.nuget.org/packages/Enferno.Services.StormConnect.Contracts/
static void Main()
{
    var serviceUrl = "https://demo.api-se.norce.tech/commerce/connect/4.0/";
    var applicationId = 0;
    var secretKey = Guid.NewGuid();

    var job = ImportProduct(serviceUrl, applicationId, secretKey);
}

public static JobDto ImportProduct(string serviceUrl, int applicationId, Guid secretKey)
{
    const int accountId = 0;

    var productHeader = new ProductHeader()
    {
        AccountId = accountId,
        FullFile = false,
        ProductFieldsThatAreSet = new List<ProductField>()
        {
            ProductField.ManufacturerCode,
            ProductField.Variants,
            ProductField.Cultures,
            ProductField.Categories
        },
        ProductCultureFieldsThatAreSet = new List<ProductCultureField>
        {
            ProductCultureField.Name,
            ProductCultureField.Description,
            ProductCultureField.Title
        },
        VariantFieldsThatAreSet = new List<VariantField>
        {
            VariantField.ManufacturerPartNo,
            VariantField.Skus
        },
        VariantCultureFieldsThatAreSet = new List<VariantCultureField>
        {
        },
        SkuFieldsThatAreSet = new List<SkuField>
        {
            SkuField.Status,
            SkuField.Type,
            SkuField.VatRate
        },
        SkuCultureFieldsThatAreSet = new List<SkuCultureField>
        {
            SkuCultureField.ErpName,
            SkuCultureField.Comment
        },
        SkuPriceListFieldsThatAreSet = new List<SkuPriceListField>
        {
        },
        IgnoreSkuPriceListFieldsWhenEmpty = new List<SkuPriceListField>
        {
        },
        SkuStructureItemFieldsThatAreSet = new List<SkuStructureItemField>
        {
        }
    };

    var requestUri = new Uri(new Uri(serviceUrl), "product/ImportProducts");
    var myRequest = new MyRequest<ProductHeader, Product>(productHeader, GetProducts());
    return RestHelper.SendStreamedData<JobDto, ProductHeader, Product>(
        requestUri.AbsoluteUri, applicationId, secretKey, myRequest);
}

private static IEnumerable<Product> GetProducts()
{
    return new List<Product>
    {
        new Product
        {
            ManufacturerCode = "MFR0000001",           // Required key
            Variants = new List<Variant>
            {
                new Variant
                {
                    ManufacturerPartNo = "MFRPARTNOTEST01", // Required key
                    Skus = new List<Sku>
                    {
                        new Sku
                        {
                            PartNo = "TESTSKU01",      // Required key
                            Status = SkuStatus.Active, // Required
                            Type = SkuType.Standard,   // Required
                            VatRates = new List<VatRate>
                            {
                                new VatRate
                                {
                                    Rate = 25.00M,
                                    SalesArea = SalesArea.Sweden
                                }
                            },
                            Cultures = new List<SkuCulture>
                            {
                                new SkuCulture
                                {
                                    CultureCode = "sv-SE",
                                    ErpName = "ERP Name",
                                    Comment = "Comment"
                                }
                            }
                        }
                    }
                }
            },
            Cultures = new List<ProductCulture>
            {
                new ProductCulture
                {
                    CultureCode = "sv-SE",
                    Name = "Name",
                    Description = "Description",
                    Title = "Title"
                }
            },
            Categories = new List<ProductCategory>
            {
                new ProductCategory
                {
                    Code = "CAT001",
                    SortOrder = 1
                }
            }
        }
    };
}

ImportOnHands

View .NET code sample
// Using Storm Client library: https://github.com/StormCommerce/Storm.Connect.Contracts
// NuGet: https://www.nuget.org/packages/Enferno.Services.StormConnect.Contracts/
static void Main()
{
    var serviceUrl = "https://demo.api-se.norce.tech/commerce/connect/4.0/";
    var applicationId = 0;
    var secretKey = Guid.NewGuid();

    var job = ImportSkuOnhand(serviceUrl, applicationId, secretKey);
}

public static JobDto ImportSkuOnhand(string serviceUrl, int applicationId, Guid secretKey)
{
    const int accountId = 0;

    var onhandHeader = new SkuOnhandHeader
    {
        AccountId = accountId,
        FullFile = false,
        SkuOnhandFieldsThatAreSet = new List<SkuOnhandField>()
        {
            SkuOnhandField.OnhandValue,
            SkuOnhandField.IncomingValue,
            SkuOnhandField.NextDeliveryDate,
            SkuOnhandField.LeadTimeDayCount
        }
    };

    var requestUri = new Uri(new Uri(serviceUrl), "product/ImportOnhands");
    var myRequest = new MyRequest<SkuOnhandHeader, SkuOnhand>(onhandHeader, GetOnhands());
    return RestHelper.SendStreamedData<JobDto, SkuOnhandHeader, SkuOnhand>(
        requestUri.AbsoluteUri, applicationId, secretKey, myRequest);
}

private static IEnumerable<SkuOnhand> GetOnhands()
{
    return new List<SkuOnhand>
    {
        new SkuOnhand
        {
            PartNo = "PartNo123",          // Required key
            WarehouseCode = "Warehouse1",  // Required key
            LocationCode = "Location1",    // Required key
            OnhandValue = 1.0M,
            IncomingValue = 2.0M,
            NextDeliveryDate = DateTime.Now.AddDays(2),
            LeadTimeDayCount = null
        }
    };
}

ImportSkuPriceLists

View .NET code sample
// Using Storm Client library: https://github.com/StormCommerce/Storm.Connect.Contracts
// NuGet: https://www.nuget.org/packages/Enferno.Services.StormConnect.Contracts/
static void Main()
{
    var serviceUrl = "https://demo.api-se.norce.tech/commerce/connect/4.0/";
    var applicationId = 0;
    var secretKey = Guid.NewGuid();

    var job = ImportSkuPriceList(serviceUrl, applicationId, secretKey);
}

public static JobDto ImportSkuPriceList(string serviceUrl, int applicationId, Guid secretKey)
{
    const int accountId = 0;

    var priceListHeader = new SkuPriceListHeader
    {
        AccountId = accountId,
        FullFile = false,
        SkuPriceListFieldsThatAreSet = new List<SkuPriceListField>()
        {
            SkuPriceListField.PriceSale,
            SkuPriceListField.CostPurchase
        }
    };

    var requestUri = new Uri(new Uri(serviceUrl), "product/ImportSkuPriceLists");
    var myRequest = new MyRequest<SkuPriceListHeader, SkuPriceList>(priceListHeader, GetPriceLists());
    return RestHelper.SendStreamedData<JobDto, SkuPriceListHeader, SkuPriceList>(
        requestUri.AbsoluteUri, applicationId, secretKey, myRequest);
}

private static IEnumerable<SkuPriceList> GetPriceLists()
{
    return new List<SkuPriceList>
    {
        new SkuPriceList
        {
            PartNo = "PartNo123",           // Required key
            PriceListCode = "PriceList1",   // Required key
            QuantityBreak = 1,              // Required key
            PriceSale = 2.00M,              // Excl. VAT
            CostPurchase = 1.00M            // Excl. VAT
        }
    };
}