ProductInventoryUpdate Endpoint

Overview

It wouldn't be unusual to need to update existing product inventory.  This endpoint allows you to update any specific product's inventory in your store.

Requirements

The following pre-requisites will be necessary to accomplish the goals of this article:

  • General understanding of REST and API’s
  • Understanding of C# and/or JavaScript
  • Visual Studio 2012 or newer

Getting Started

You should already have a project open and ready to accept code to allow you to use this REST API endpoint.  You should also have one or more products with inventory created so that you can successfully find one to update.

ProductInventoryUpdate

This REST API endpoint allows you to update a product's inventory in your store. This requires that you also have a category to update, which would mean that you should also call the ProductInventoryFind endpoint to get an existing product inventory object.

Example URL

This is what the REST endpoint will look like if you are calling it using JavaScript.  See our REST API URL documentation for more information.

http://example.com/DesktopModules/Hotcakes/API/rest/v1/productinventory/[BVIN]

HTTP Method

POST

Parameters

Parameter Description
bvin This is the unique ID of the product inventory that you wish to update
data You will need to pass an updated JSON version of the ProductInventoryDTO object in your post request

Returns

If successful, this endpoint will return a populated ProductInventoryDTO object in JSON format.  Otherwise, you should have one or more errors returned.  

Example Code

The following code will allow you to successfully call this endpoint, provided that you have enabled it.

Project References

  • Hotcakes.CommerceDTO

Import Namespaces

  • Hotcakes.CommerceDTO.v1
  • Hotcakes.CommerceDTO.v1.Catalog
  • Hotcakes.CommerceDTO.v1.Client

 

string url = "http://example.com";
string key = "YOUR-API-KEY";

Api proxy = new Api(url, key);

// specify the product inventory object to find
var inventoryId = "f82bcaad-97e4-4e03-8683-998a09346009";

// call the API to get the product inventory record
var inventory = proxy.ProductInventoryFind(inventoryId).Content;

// update one or more inventory properties
inventory.QuantityReserved = 20;

// call the API to create the new product inventory record
ApiResponse<ProductInventoryDTO> response = proxy.ProductInventoryUpdate(inventory);
// your domain name
var url = "http://example.com"; 
// the path where the API is
var apiPath = "/DesktopModules/Hotcakes/API/rest/v1/";  
// endpoint as shown in the documentation
var endPoint = "productinventory";  
// get this from the store admin
var apiKey = "YOUR-API-KEY";

$(document).ready(function() {

    // specify the product inventory object to find
    var inventoryId = "f82bcaad-97e4-4e03-8683-998a09346009";

    // call the API to find the product inventory record
    $.ajax({
        dataType: "json",
        url: url + apiPath + endPoint + "/" + inventoryId + "?key=" + apiKey,
        type: 'GET',
        success: function (data) {
            // update the product inventory in another method
            UpdateProductInventory(data.Content);
        },
        error: function (jqXHR, textStatus) {
            // do something
        }
    });

});

function UpdateProductInventory(inventory) {

    // update one or more inventory properties
    inventory.QuantityReserved = 20;

    // replace date properties with UTC-friendly dates to prevent errors
    inventory.LastUpdated = ParseDateForSave(inventory.LastUpdated);

    // call the API to find the product inventory record
    $.ajax({
        dataType: "json",
        url: url + apiPath + endPoint + "/" + inventory.Bvin + "?key=" + apiKey,
        data: JSON.stringify(inventory),
        type: 'POST',
        success: function (data) {
            // do something
        },
        error: function (jqXHR, textStatus) {
            // do something else
        }
    });

}

function ParseDateForSave(dateValue) {
    // create a new date object in UTC format
    var newDate = new Date(parseInt(dateValue.substr(6)));

    // return the UTC version of the date
    return newDate.toISOString();
}
{
   "Errors":[

   ],
   "Content":{
      "Bvin":"f82bcaad-97e4-4e03-8683-998a09346009",
      "LastUpdated":"\/Date(1401945811373)\/",
      "ProductBvin":"dfcae0ee-8bcf-4321-8b31-7883b5434285",
      "VariantId":"",
      "QuantityOnHand":100,
      "QuantityReserved":20,
      "LowStockPoint":10,
      "OutOfStockPoint":3
   }
}
Have more questions? Submit a request

Need More Help?

Do you need more assistance with this article? Please review your support options.