Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) Faire - Update Inventory LevelsSee more Faire ExamplesUpdate the inventory levels for multiple product options in one request. For more information, see https://faire.github.io/external-api-docs/#update-inventory-levels
LOCAL loHttp LOCAL lnSuccess LOCAL loJson LOCAL loSbRequestBody LOCAL loResp LOCAL loSbResponseBody LOCAL loJResp LOCAL lnRespStatusCode LOCAL lcId LOCAL lcProduct_id LOCAL lnActive LOCAL lnDeleted LOCAL lcName LOCAL lcSku LOCAL lnAvailable_quantity LOCAL lcCreated_at LOCAL lcUpdated_at LOCAL lnRetail_price_cents LOCAL lnWholesale_price_cents LOCAL lcBackordered_until LOCAL j LOCAL lnCount_j LOCAL lcValue LOCAL i LOCAL lnCount_i * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('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 * } * ] * } * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJson = CreateObject('Chilkat.JsonObject') loJson.UpdateString("inventories[0].sku","vanilla-candle") loJson.UpdateInt("inventories[0].current_quantity",24) loJson.UpdateBool("inventories[0].discontinued",0) loJson.UpdateNull("inventories[0].backordered_until") loJson.UpdateString("inventories[1].sku","cinnamon-candle") loJson.UpdateInt("inventories[1].current_quantity",0) loJson.UpdateBool("inventories[1].discontinued",0) loJson.UpdateString("inventories[1].backordered_until","20190314T000915.000Z") loJson.UpdateString("inventories[2].sku","fall-candle") loJson.UpdateInt("inventories[2].current_quantity",0) loJson.UpdateBool("inventories[2].discontinued",1) loJson.UpdateNull("inventories[2].backordered_until") loJson.UpdateString("inventories[3].sku","fall-candle") loJson.UpdateNull("inventories[3].current_quantity") loJson.UpdateBool("inventories[3].discontinued",0) loJson.UpdateNull("inventories[3].backordered_until") loHttp.SetRequestHeader("Content-Type","application/json") loHttp.SetRequestHeader("X-FAIRE-ACCESS-TOKEN","<access_token>") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbRequestBody = CreateObject('Chilkat.StringBuilder') loJson.EmitSb(loSbRequestBody) loResp = loHttp.PTextSb("PATCH","https://www.faire.com/api/v1/products/options/inventory-levels",loSbRequestBody,"utf-8","application/json",0,0) IF (loHttp.LastMethodSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loJson RELEASE loSbRequestBody CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponseBody = CreateObject('Chilkat.StringBuilder') loResp.GetBodySb(loSbResponseBody) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJResp = CreateObject('Chilkat.JsonObject') loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = 0 ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + STR(lnRespStatusCode) IF (lnRespStatusCode >= 400) THEN ? "Response Header:" ? loResp.Header ? "Failed." RELEASE loResp RELEASE loHttp RELEASE loJson RELEASE loSbRequestBody RELEASE loSbResponseBody RELEASE loJResp CANCEL ENDIF RELEASE loResp * 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 i = 0 lnCount_i = loJResp.SizeOfArray("options") DO WHILE i < lnCount_i loJResp.I = i lcId = loJResp.StringOf("options[i].id") lcProduct_id = loJResp.StringOf("options[i].product_id") lnActive = loJResp.BoolOf("options[i].active") lnDeleted = loJResp.BoolOf("options[i].deleted") lcName = loJResp.StringOf("options[i].name") lcSku = loJResp.StringOf("options[i].sku") lnAvailable_quantity = loJResp.IntOf("options[i].available_quantity") lcCreated_at = loJResp.StringOf("options[i].created_at") lcUpdated_at = loJResp.StringOf("options[i].updated_at") lnRetail_price_cents = loJResp.IntOf("options[i].retail_price_cents") lnWholesale_price_cents = loJResp.IntOf("options[i].wholesale_price_cents") lcBackordered_until = loJResp.StringOf("options[i].backordered_until") j = 0 lnCount_j = loJResp.SizeOfArray("options[i].variations") DO WHILE j < lnCount_j loJResp.J = j lcName = loJResp.StringOf("options[i].variations[j].name") lcValue = loJResp.StringOf("options[i].variations[j].value") j = j + 1 ENDDO i = i + 1 ENDDO RELEASE loHttp RELEASE loJson RELEASE loSbRequestBody RELEASE loSbResponseBody RELEASE loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.