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
(Lianja) Lightspeed - Create a ProductCreate a new product based on the given parameters. For more information, see https://developers.lightspeedhq.com/ecom/endpoints/product/#post-create-a-product
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loHttp = createobject("CkHttp") // Implements the following CURL command: // curl -u API_KEY:API_SECRET \ // -H "Content-Type: application/json" \ // -X POST \ // -d '{ // "product": { // "visibility": "visible", // "data01": "", // "data02": "", // "data03": "", // "title": "Lookin Sharp T-Shirt", // "fulltitle": "Lookin Sharp T-Shirt", // "description": "Description of the Lookin Sharp T-Shirt", // "content": "Long Description of the Lookin Sharp T-Shirt", // "deliverydate": 6488, // "supplier": 78794, // "brand": 1171202 // } // }' \ // "https://api.webshopapp.com/en/products.json" // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code loHttp.Login = "API_KEY" loHttp.Password = "API_SECRET" // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "product": { // "visibility": "visible", // "data01": "", // "data02": "", // "data03": "", // "title": "Lookin Sharp T-Shirt", // "fulltitle": "Lookin Sharp T-Shirt", // "description": "Description of the Lookin Sharp T-Shirt", // "content": "Long Description of the Lookin Sharp T-Shirt", // "deliverydate": 6488, // "supplier": 78794, // "brand": 1171202 // } // } loJson = createobject("CkJsonObject") loJson.UpdateString("product.visibility","visible") loJson.UpdateString("product.data01","") loJson.UpdateString("product.data02","") loJson.UpdateString("product.data03","") loJson.UpdateString("product.title","Lookin Sharp T-Shirt") loJson.UpdateString("product.fulltitle","Lookin Sharp T-Shirt") loJson.UpdateString("product.description","Description of the Lookin Sharp T-Shirt") loJson.UpdateString("product.content","Long Description of the Lookin Sharp T-Shirt") loJson.UpdateInt("product.deliverydate",6488) loJson.UpdateInt("product.supplier",78794) loJson.UpdateInt("product.brand",1171202) loHttp.SetRequestHeader("Content-Type","application/json") // Use the correct cluster for your shop. Here are the choices: // eu1 https://api.webshopapp.com/en/ // us1 https://api.shoplightspeed.com/en/ loResp = loHttp.PostJson3("https://api.webshopapp.com/en/products.json","application/json",loJson) if (loHttp.LastMethodSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loJson return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "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 loSbResponseBody release loJResp return endif release loResp // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "product": { // "id": 20974460, // "createdAt": "2019-05-28T20:14:26+00:00", // "updatedAt": "2019-05-28T20:14:26+00:00", // "isVisible": true, // "visibility": "visible", // "hasMatrix": false, // "data01": "", // "data02": "", // "data03": "", // "url": "lookin-sharp-t-shirt", // "title": "Lookin' Sharp T-Shirt", // "fulltitle": "Lookin' Sharp T-Shirt", // "description": "Description of the Lookin' Sharp T-Shirt", // "content": "<p>Long Description of the Lookin' Sharp T-Shirt</p>", // "set": false, // "brand": { // "resource": { // "id": 1171202, // "url": "brands/1171202", // "link": "https://api.shoplightspeed.com/us/brands/1171202.json" // } // }, // "categories": { // "resource": { // "id": false, // "url": "categories/products?product=20974460", // "link": "https://api.shoplightspeed.com/us/categories/products.json?product=20974460" // } // }, // "deliverydate": { // "resource": { // "id": 6488, // "url": "deliverydates/6488", // "link": "https://api.shoplightspeed.com/us/deliverydates/6488.json" // } // }, // "image": false, // "images": false, // "relations": { // "resource": { // "id": false, // "url": "products/20974460/relations", // "link": "https://api.shoplightspeed.com/us/products/20974460/relations.json" // } // }, // "metafields": { // "resource": { // "id": false, // "url": "products/20974460/metafields", // "link": "https://api.shoplightspeed.com/us/products/20974460/metafields.json" // } // }, // "reviews": { // "resource": { // "id": false, // "url": "reviews?product=20974460", // "link": "https://api.shoplightspeed.com/us/reviews.json?product=20974460" // } // }, // "type": false, // "attributes": { // "resource": { // "id": false, // "url": "products/20974460/attributes", // "link": "https://api.shoplightspeed.com/us/products/20974460/attributes.json" // } // }, // "supplier": { // "resource": { // "id": 78794, // "url": "suppliers/78794", // "link": "https://api.shoplightspeed.com/us/suppliers/78794.json" // } // }, // "tags": { // "resource": { // "id": false, // "url": "tags/products?product=20974460", // "link": "https://api.shoplightspeed.com/us/tags/products.json?product=20974460" // } // }, // "variants": { // "resource": { // "id": false, // "url": "variants?product=20974460", // "link": "https://api.shoplightspeed.com/us/variants.json?product=20974460" // } // }, // "movements": { // "resource": { // "id": false, // "url": "variants/movements?product=20974460", // "link": "https://api.shoplightspeed.com/us/variants/movements.json?product=20974460" // } // } // } // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON lnProductId = loJResp.IntOf("product.id") lcProductCreatedAt = loJResp.StringOf("product.createdAt") lcProductUpdatedAt = loJResp.StringOf("product.updatedAt") llProductIsVisible = loJResp.BoolOf("product.isVisible") lcProductVisibility = loJResp.StringOf("product.visibility") llProductHasMatrix = loJResp.BoolOf("product.hasMatrix") lcProductData01 = loJResp.StringOf("product.data01") lcProductData02 = loJResp.StringOf("product.data02") lcProductData03 = loJResp.StringOf("product.data03") lcProductUrl = loJResp.StringOf("product.url") lcProductTitle = loJResp.StringOf("product.title") lcProductFulltitle = loJResp.StringOf("product.fulltitle") lcProductDescription = loJResp.StringOf("product.description") lcProductContent = loJResp.StringOf("product.content") llProductSet = loJResp.BoolOf("product.set") lnProductBrandResourceId = loJResp.IntOf("product.brand.resource.id") lcProductBrandResourceUrl = loJResp.StringOf("product.brand.resource.url") lcProductBrandResourceLink = loJResp.StringOf("product.brand.resource.link") llProductCategoriesResourceId = loJResp.BoolOf("product.categories.resource.id") lcProductCategoriesResourceUrl = loJResp.StringOf("product.categories.resource.url") lcProductCategoriesResourceLink = loJResp.StringOf("product.categories.resource.link") lnProductDeliverydateResourceId = loJResp.IntOf("product.deliverydate.resource.id") lcProductDeliverydateResourceUrl = loJResp.StringOf("product.deliverydate.resource.url") lcProductDeliverydateResourceLink = loJResp.StringOf("product.deliverydate.resource.link") llProductImage = loJResp.BoolOf("product.image") llProductImages = loJResp.BoolOf("product.images") llProductRelationsResourceId = loJResp.BoolOf("product.relations.resource.id") lcProductRelationsResourceUrl = loJResp.StringOf("product.relations.resource.url") lcProductRelationsResourceLink = loJResp.StringOf("product.relations.resource.link") llProductMetafieldsResourceId = loJResp.BoolOf("product.metafields.resource.id") lcProductMetafieldsResourceUrl = loJResp.StringOf("product.metafields.resource.url") lcProductMetafieldsResourceLink = loJResp.StringOf("product.metafields.resource.link") llProductReviewsResourceId = loJResp.BoolOf("product.reviews.resource.id") lcProductReviewsResourceUrl = loJResp.StringOf("product.reviews.resource.url") lcProductReviewsResourceLink = loJResp.StringOf("product.reviews.resource.link") llProductType = loJResp.BoolOf("product.type") llProductAttributesResourceId = loJResp.BoolOf("product.attributes.resource.id") lcProductAttributesResourceUrl = loJResp.StringOf("product.attributes.resource.url") lcProductAttributesResourceLink = loJResp.StringOf("product.attributes.resource.link") lnProductSupplierResourceId = loJResp.IntOf("product.supplier.resource.id") lcProductSupplierResourceUrl = loJResp.StringOf("product.supplier.resource.url") lcProductSupplierResourceLink = loJResp.StringOf("product.supplier.resource.link") llProductTagsResourceId = loJResp.BoolOf("product.tags.resource.id") lcProductTagsResourceUrl = loJResp.StringOf("product.tags.resource.url") lcProductTagsResourceLink = loJResp.StringOf("product.tags.resource.link") llProductVariantsResourceId = loJResp.BoolOf("product.variants.resource.id") lcProductVariantsResourceUrl = loJResp.StringOf("product.variants.resource.url") lcProductVariantsResourceLink = loJResp.StringOf("product.variants.resource.link") llProductMovementsResourceId = loJResp.BoolOf("product.movements.resource.id") lcProductMovementsResourceUrl = loJResp.StringOf("product.movements.resource.url") lcProductMovementsResourceLink = loJResp.StringOf("product.movements.resource.link") release loHttp release loJson release loSbResponseBody release loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.