Xbase++ Requires Chilkat v11.0.0+
Xbase++
Shopify Update Inventory Level for a Product (Adjust available quantity)
See more Shopify Examples
Use the adjust endpoint with the location ID and inventory item ID to increase or decrease the available quantity for an inventory level:Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonRequestBody
LOCAL cUrl
LOCAL oResp
LOCAL oJsonResponse
LOCAL nInventory_levelInventory_item_id
LOCAL nInventory_levelLocation_id
LOCAL nInventory_levelAvailable
LOCAL cInventory_levelUpdated_at
LOCAL cInventory_levelAdmin_graphql_api_id
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:Login := "SHOPIFY_PRIVATE_API_KEY"
oHttp:Password := "SHOPIFY_PRIVATE_API_KEY"
// Also see: How to retrieve inventory levels
oHttp:Accept := "application/json"
// The following JSON is sent in the request body:
// {
// "location_id": 6884556842,
// "inventory_item_id": 12250274365496,
// "available_adjustment": 1
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
oJsonRequestBody := CreateObject("Chilkat.JsonObject")
oJsonRequestBody:UpdateInt("location_id", 6884556842)
oJsonRequestBody:UpdateInt("inventory_item_id", 12250274365496)
oJsonRequestBody:UpdateInt("available_adjustment", 1)
cUrl := "https://{shop}.myshopify.com/admin/api/2020-04/inventory_levels/adjust.json"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", cUrl, oJsonRequestBody, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
RETURN
ENDIF
? "Response Status Code: " + Str(oResp:StatusCode)
oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(oResp:BodyStr)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()
IF (oResp:StatusCode >= 300)
? "Failed."
oHttp:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
oJsonResponse:destroy()
RETURN
ENDIF
// Sample output...
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "inventory_level": {
// "inventory_item_id": 12250274365496,
// "location_id": 6884556842,
// "available": 9,
// "updated_at": "2018-06-26T15:04:49-04:00",
// ...
// "admin_graphql_api_id": "gid://shopify/InventoryLevel/6485147690?inventory_item_id=12250274365496"
// ...
// }
// }
//
nInventory_levelInventory_item_id := oJsonResponse:IntOf("inventory_level.inventory_item_id")
nInventory_levelLocation_id := oJsonResponse:IntOf("inventory_level.location_id")
nInventory_levelAvailable := oJsonResponse:IntOf("inventory_level.available")
cInventory_levelUpdated_at := oJsonResponse:StringOf("inventory_level.updated_at")
cInventory_levelAdmin_graphql_api_id := oJsonResponse:StringOf("inventory_level.admin_graphql_api_id")
oHttp:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
oJsonResponse:destroy()