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
(Swift 3,4,5...) 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
func chilkatTest() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let http = CkoHttp()! var success: Bool // 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 // } // ] // } let json = CkoJsonObject()! json.update("inventories[0].sku", value: "vanilla-candle") json.updateInt("inventories[0].current_quantity", value: 24) json.updateBool("inventories[0].discontinued", value: false) json.updateNull("inventories[0].backordered_until") json.update("inventories[1].sku", value: "cinnamon-candle") json.updateInt("inventories[1].current_quantity", value: 0) json.updateBool("inventories[1].discontinued", value: false) json.update("inventories[1].backordered_until", value: "20190314T000915.000Z") json.update("inventories[2].sku", value: "fall-candle") json.updateInt("inventories[2].current_quantity", value: 0) json.updateBool("inventories[2].discontinued", value: true) json.updateNull("inventories[2].backordered_until") json.update("inventories[3].sku", value: "fall-candle") json.updateNull("inventories[3].current_quantity") json.updateBool("inventories[3].discontinued", value: false) json.updateNull("inventories[3].backordered_until") http.setRequestHeader("Content-Type", value: "application/json") http.setRequestHeader("X-FAIRE-ACCESS-TOKEN", value: "<access_token>") let sbRequestBody = CkoStringBuilder()! json.emitSb(sbRequestBody) var resp: CkoHttpResponse? = http.pTextSb("PATCH", url: "https://www.faire.com/api/v1/products/options/inventory-levels", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false) if http.lastMethodSuccess == false { print("\(http.lastErrorText!)") return } let sbResponseBody = CkoStringBuilder()! resp!.getBodySb(sbResponseBody) let jResp = CkoJsonObject()! jResp.loadSb(sbResponseBody) jResp.emitCompact = false print("Response Body:") print("\(jResp.emit()!)") var respStatusCode: Int = resp!.statusCode.intValue print("Response Status Code = \(respStatusCode)") if respStatusCode >= 400 { print("Response Header:") print("\(resp!.header!)") print("Failed.") resp = nil return } resp = nil // 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 var id: String? var product_id: String? var active: Bool var deleted: Bool var name: String? var sku: String? var available_quantity: Int var created_at: String? var updated_at: String? var retail_price_cents: Int var wholesale_price_cents: Int var backordered_until: String? var j: Int var count_j: Int var value: String? var i: Int = 0 var count_i: Int = jResp.size(ofArray: "options").intValue while i < count_i { jResp.i = i id = jResp.string(of: "options[i].id") product_id = jResp.string(of: "options[i].product_id") active = jResp.bool(of: "options[i].active") deleted = jResp.bool(of: "options[i].deleted") name = jResp.string(of: "options[i].name") sku = jResp.string(of: "options[i].sku") available_quantity = jResp.int(of: "options[i].available_quantity").intValue created_at = jResp.string(of: "options[i].created_at") updated_at = jResp.string(of: "options[i].updated_at") retail_price_cents = jResp.int(of: "options[i].retail_price_cents").intValue wholesale_price_cents = jResp.int(of: "options[i].wholesale_price_cents").intValue backordered_until = jResp.string(of: "options[i].backordered_until") j = 0 count_j = jResp.size(ofArray: "options[i].variations").intValue while j < count_j { jResp.j = j name = jResp.string(of: "options[i].variations[j].name") value = jResp.string(of: "options[i].variations[j].value") j = j + 1 } i = i + 1 } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.