Sample code for 30+ languages & platforms
Xojo Plugin

Faire - Update Inventory Levels

See more Faire Examples

Update the inventory levels for multiple product options in one request.

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

Dim http As New Chilkat.Http

// Implements the following CURL command:

// curl -X PATCH 
//     -H "Content-Type: application/json" 
//     -H "X-FAIRE-ACCESS-TOKEN: <access_token>"
//     -d '{
//   "inventories": [
//     {
//       "sku": "vanilla-candle",
//       "current_quantity": 24,
//       "discontinued": false,
//       "backordered_until": null
//     },
//     {
//       "sku": "cinnamon-candle",
//       "current_quantity": 0,
//       "discontinued": false,
//       "backordered_until": "20190314T000915.000Z"
//     },
//     {
//       "sku": "fall-candle",
//       "current_quantity": 0,
//       "discontinued": true,
//       "backordered_until": null
//     },
//     {
//       "sku": "fall-candle",
//       "current_quantity": null,
//       "discontinued": false,
//       "backordered_until": null
//     }
//   ]
// }' https://www.faire.com/api/v1/products/options/inventory-levels

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "inventories": [
//     {
//       "sku": "vanilla-candle",
//       "current_quantity": 24,
//       "discontinued": false,
//       "backordered_until": null
//     },
//     {
//       "sku": "cinnamon-candle",
//       "current_quantity": 0,
//       "discontinued": false,
//       "backordered_until": "20190314T000915.000Z"
//     },
//     {
//       "sku": "fall-candle",
//       "current_quantity": 0,
//       "discontinued": true,
//       "backordered_until": null
//     },
//     {
//       "sku": "fall-candle",
//       "current_quantity": null,
//       "discontinued": false,
//       "backordered_until": null
//     }
//   ]
// }

Dim json As New Chilkat.JsonObject
success = json.UpdateString("inventories[0].sku","vanilla-candle")
success = json.UpdateInt("inventories[0].current_quantity",24)
success = json.UpdateBool("inventories[0].discontinued",False)
success = json.UpdateNull("inventories[0].backordered_until")
success = json.UpdateString("inventories[1].sku","cinnamon-candle")
success = json.UpdateInt("inventories[1].current_quantity",0)
success = json.UpdateBool("inventories[1].discontinued",False)
success = json.UpdateString("inventories[1].backordered_until","20190314T000915.000Z")
success = json.UpdateString("inventories[2].sku","fall-candle")
success = json.UpdateInt("inventories[2].current_quantity",0)
success = json.UpdateBool("inventories[2].discontinued",True)
success = json.UpdateNull("inventories[2].backordered_until")
success = json.UpdateString("inventories[3].sku","fall-candle")
success = json.UpdateNull("inventories[3].current_quantity")
success = json.UpdateBool("inventories[3].discontinued",False)
success = json.UpdateNull("inventories[3].backordered_until")

http.SetRequestHeader "Content-Type","application/json"
http.SetRequestHeader "X-FAIRE-ACCESS-TOKEN","<access_token>"

Dim sbRequestBody As New Chilkat.StringBuilder
success = json.EmitSb(sbRequestBody)

Dim resp As New Chilkat.HttpResponse
success = http.HttpSb("PATCH","https://www.faire.com/api/v1/products/options/inventory-levels",sbRequestBody,"utf-8","application/json",resp)
If (success = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

Dim sbResponseBody As New Chilkat.StringBuilder
success = resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

System.DebugLog("Response Body:")
System.DebugLog(jResp.Emit())

Dim respStatusCode As Int32
respStatusCode = resp.StatusCode
System.DebugLog("Response Status Code = " + Str(respStatusCode))
If (respStatusCode >= 400) Then
    System.DebugLog("Response Header:")
    System.DebugLog(resp.Header)
    System.DebugLog("Failed.")
    Return
End If

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "options": [
//     {
//       "id": "po_012",
//       "product_id": "p_ghi",
//       "active": false,
//       "deleted": false,
//       "name": "Fall Scent",
//       "sku": "fall-candle",
//       "available_quantity": 0,
//       "created_at": "20190313T000915.000Z",
//       "updated_at": "20190315T000915.000Z",
//       "variations": [
//         {
//           "name": "Scent",
//           "value": "Fall"
//         }
//       ],
//       "retail_price_cents": 599,
//       "wholesale_price_cents": 300
//     },
//     {
//       "id": "po_789",
//       "product_id": "p_def",
//       "active": false,
//       "deleted": false,
//       "name": "Cinnamon Scent",
//       "sku": "cinnamon-candle",
//       "available_quantity": 0,
//       "created_at": "20190312T000915.000Z",
//       "updated_at": "20190315T000915.000Z",
//       "backordered_until": "20190314T000915.000Z",
//       "variations": [
//         {
//           "name": "Scent",
//           "value": "Cinnamon"
//         }
//       ],
//       "retail_price_cents": 599,
//       "wholesale_price_cents": 300
//     },
//     {
//       "id": "po_456",
//       "product_id": "p_abc",
//       "active": true,
//       "deleted": false,
//       "name": "Vanilla Scent",
//       "sku": "vanilla-candle",
//       "available_quantity": 24,
//       "created_at": "20190314T000915.000Z",
//       "updated_at": "20190315T000915.000Z",
//       "variations": [
//         {
//           "name": "Scent",
//           "value": "Vanilla"
//         }
//       ],
//       "retail_price_cents": 599,
//       "wholesale_price_cents": 300
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

Dim id As String
Dim product_id As String
Dim active As Boolean
Dim deleted As Boolean
Dim name As String
Dim sku As String
Dim available_quantity As Int32
Dim created_at As String
Dim updated_at As String
Dim retail_price_cents As Int32
Dim wholesale_price_cents As Int32
Dim backordered_until As String
Dim j As Int32
Dim count_j As Int32
Dim value As String

Dim i As Int32
i = 0
Dim count_i As Int32
count_i = jResp.SizeOfArray("options")
While i < count_i
    jResp.I = i
    id = jResp.StringOf("options[i].id")
    product_id = jResp.StringOf("options[i].product_id")
    active = jResp.BoolOf("options[i].active")
    deleted = jResp.BoolOf("options[i].deleted")
    name = jResp.StringOf("options[i].name")
    sku = jResp.StringOf("options[i].sku")
    available_quantity = jResp.IntOf("options[i].available_quantity")
    created_at = jResp.StringOf("options[i].created_at")
    updated_at = jResp.StringOf("options[i].updated_at")
    retail_price_cents = jResp.IntOf("options[i].retail_price_cents")
    wholesale_price_cents = jResp.IntOf("options[i].wholesale_price_cents")
    backordered_until = jResp.StringOf("options[i].backordered_until")
    j = 0
    count_j = jResp.SizeOfArray("options[i].variations")
    While j < count_j
        jResp.J = j
        name = jResp.StringOf("options[i].variations[j].name")
        value = jResp.StringOf("options[i].variations[j].value")
        j = j + 1
    Wend
    i = i + 1
Wend