Contact me!
Eric Håård
+46 (0) 73 375 86 06

ImportProduct

C# example code for the ImportProduct method.

Used to insert new or update products in Storm Commerce, required keys are:

  • ManufacturerCode – Manufacturer Code in Storm
  • ManufacturerPartNo – Combination of ManufacturerCode and ManufacturerPartNo must be unique
  • PartNo – SKU identifier
  • Status – SKU status enum
  • Type – SKU type enum

Example code:

static void Main()
{
    var serviceUrl = "https://stormstage.enferno.se/StormConnect/4.0/api/";
    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()
{
    // NOTE Format and map your data to the StormConnect standard here
    return new List<Product>
    {
        new Product
        {
            ManufacturerCode = "MFR0000001", // NOTE Required key
            Variants = new List<Variant>
            {
                new Variant
                {
                    ManufacturerPartNo = "MFRPARTNOTEST01", // NOTE Required key
                    Skus = new List<Sku>
                    {
                        new Sku
                        {
                            PartNo = "TESTSKU01", // NOTE Required key
                            Status = SkuStatus.Active, // NOTE Required key
                            Type = SkuType.Standard, // NOTE Required key
                            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
                }
            }
        }
    };
}

Related:
Querying job status