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
(PowerBuilder) 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
integer li_rc oleobject loo_Http integer li_Success oleobject loo_Json oleobject loo_SbRequestBody oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_Id string ls_Product_id integer li_Active integer li_Deleted string ls_Name string ls_Sku integer li_Available_quantity string ls_Created_at string ls_Updated_at integer li_Retail_price_cents integer li_Wholesale_price_cents string ls_Backordered_until integer j integer li_Count_j string ls_Value integer i integer li_Count_i // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // 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 // } // ] // } loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateString("inventories[0].sku","vanilla-candle") loo_Json.UpdateInt("inventories[0].current_quantity",24) loo_Json.UpdateBool("inventories[0].discontinued",0) loo_Json.UpdateNull("inventories[0].backordered_until") loo_Json.UpdateString("inventories[1].sku","cinnamon-candle") loo_Json.UpdateInt("inventories[1].current_quantity",0) loo_Json.UpdateBool("inventories[1].discontinued",0) loo_Json.UpdateString("inventories[1].backordered_until","20190314T000915.000Z") loo_Json.UpdateString("inventories[2].sku","fall-candle") loo_Json.UpdateInt("inventories[2].current_quantity",0) loo_Json.UpdateBool("inventories[2].discontinued",1) loo_Json.UpdateNull("inventories[2].backordered_until") loo_Json.UpdateString("inventories[3].sku","fall-candle") loo_Json.UpdateNull("inventories[3].current_quantity") loo_Json.UpdateBool("inventories[3].discontinued",0) loo_Json.UpdateNull("inventories[3].backordered_until") loo_Http.SetRequestHeader("Content-Type","application/json") loo_Http.SetRequestHeader("X-FAIRE-ACCESS-TOKEN","<access_token>") loo_SbRequestBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Json.EmitSb(loo_SbRequestBody) loo_Resp = loo_Http.PTextSb("PATCH","https://www.faire.com/api/v1/products/options/inventory-levels",loo_SbRequestBody,"utf-8","application/json",0,0) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Json destroy loo_SbRequestBody return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Resp.Header Write-Debug "Failed." destroy loo_Resp destroy loo_Http destroy loo_Json destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // 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 li_Count_i = loo_JResp.SizeOfArray("options") do while i < li_Count_i loo_JResp.I = i ls_Id = loo_JResp.StringOf("options[i].id") ls_Product_id = loo_JResp.StringOf("options[i].product_id") li_Active = loo_JResp.BoolOf("options[i].active") li_Deleted = loo_JResp.BoolOf("options[i].deleted") ls_Name = loo_JResp.StringOf("options[i].name") ls_Sku = loo_JResp.StringOf("options[i].sku") li_Available_quantity = loo_JResp.IntOf("options[i].available_quantity") ls_Created_at = loo_JResp.StringOf("options[i].created_at") ls_Updated_at = loo_JResp.StringOf("options[i].updated_at") li_Retail_price_cents = loo_JResp.IntOf("options[i].retail_price_cents") li_Wholesale_price_cents = loo_JResp.IntOf("options[i].wholesale_price_cents") ls_Backordered_until = loo_JResp.StringOf("options[i].backordered_until") j = 0 li_Count_j = loo_JResp.SizeOfArray("options[i].variations") do while j < li_Count_j loo_JResp.J = j ls_Name = loo_JResp.StringOf("options[i].variations[j].name") ls_Value = loo_JResp.StringOf("options[i].variations[j].value") j = j + 1 loop i = i + 1 loop destroy loo_Http destroy loo_Json destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.