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

ImportSkuOnhand

C# example code for the ImportSkuOnhand method

Used to update on hand data for SKUs, keys are:

  • PartNo – SKU identifier
  • WarehouseCode – Warehouse identifier
  • LocationCode – Warehouse location identifier

SKU, Warehouse and Location must already exist in Storm Commerce, if not – data is ignored.

Example code:

static void Main()
{
    var serviceUrl = "https://stormstage.enferno.se/StormConnect/4.0/api/";
    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>()
        {
            // Creates/Updates only the below fields in the import.
            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()
{
    // NOTE Format and map your data to the StormConnect standard here
    return new List<SkuOnhand>
    {
        new SkuOnhand
        {
            PartNo = "PartNo123", // NOTE This is required key for onhand
            WarehouseCode = "Warehouse1", // NOTE This is a required key for onhand
            LocationCode = "Location1", // NOTE This is a required key for onhand
            OnhandValue = 1.0M,
            IncomingValue = 2.0M,
            NextDeliveryDate = DateTime.Now.AddDays(2),
            LeadTimeDayCount = null
        }
    };
}

Related:
Querying job status