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
(PureBasic) 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
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; 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 CkHttp::setCkLogin(http, "API_KEY") CkHttp::setCkPassword(http, "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 ; } ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"product.visibility","visible") CkJsonObject::ckUpdateString(json,"product.data01","") CkJsonObject::ckUpdateString(json,"product.data02","") CkJsonObject::ckUpdateString(json,"product.data03","") CkJsonObject::ckUpdateString(json,"product.title","Lookin Sharp T-Shirt") CkJsonObject::ckUpdateString(json,"product.fulltitle","Lookin Sharp T-Shirt") CkJsonObject::ckUpdateString(json,"product.description","Description of the Lookin Sharp T-Shirt") CkJsonObject::ckUpdateString(json,"product.content","Long Description of the Lookin Sharp T-Shirt") CkJsonObject::ckUpdateInt(json,"product.deliverydate",6488) CkJsonObject::ckUpdateInt(json,"product.supplier",78794) CkJsonObject::ckUpdateInt(json,"product.brand",1171202) CkHttp::ckSetRequestHeader(http,"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/ resp.i = CkHttp::ckPostJson3(http,"https://api.webshopapp.com/en/products.json","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; 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 productId.i = CkJsonObject::ckIntOf(jResp,"product.id") productCreatedAt.s = CkJsonObject::ckStringOf(jResp,"product.createdAt") productUpdatedAt.s = CkJsonObject::ckStringOf(jResp,"product.updatedAt") productIsVisible.i = CkJsonObject::ckBoolOf(jResp,"product.isVisible") productVisibility.s = CkJsonObject::ckStringOf(jResp,"product.visibility") productHasMatrix.i = CkJsonObject::ckBoolOf(jResp,"product.hasMatrix") productData01.s = CkJsonObject::ckStringOf(jResp,"product.data01") productData02.s = CkJsonObject::ckStringOf(jResp,"product.data02") productData03.s = CkJsonObject::ckStringOf(jResp,"product.data03") productUrl.s = CkJsonObject::ckStringOf(jResp,"product.url") productTitle.s = CkJsonObject::ckStringOf(jResp,"product.title") productFulltitle.s = CkJsonObject::ckStringOf(jResp,"product.fulltitle") productDescription.s = CkJsonObject::ckStringOf(jResp,"product.description") productContent.s = CkJsonObject::ckStringOf(jResp,"product.content") productSet.i = CkJsonObject::ckBoolOf(jResp,"product.set") productBrandResourceId.i = CkJsonObject::ckIntOf(jResp,"product.brand.resource.id") productBrandResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.brand.resource.url") productBrandResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.brand.resource.link") productCategoriesResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.categories.resource.id") productCategoriesResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.categories.resource.url") productCategoriesResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.categories.resource.link") productDeliverydateResourceId.i = CkJsonObject::ckIntOf(jResp,"product.deliverydate.resource.id") productDeliverydateResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.deliverydate.resource.url") productDeliverydateResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.deliverydate.resource.link") productImage.i = CkJsonObject::ckBoolOf(jResp,"product.image") productImages.i = CkJsonObject::ckBoolOf(jResp,"product.images") productRelationsResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.relations.resource.id") productRelationsResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.relations.resource.url") productRelationsResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.relations.resource.link") productMetafieldsResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.metafields.resource.id") productMetafieldsResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.metafields.resource.url") productMetafieldsResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.metafields.resource.link") productReviewsResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.reviews.resource.id") productReviewsResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.reviews.resource.url") productReviewsResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.reviews.resource.link") productType.i = CkJsonObject::ckBoolOf(jResp,"product.type") productAttributesResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.attributes.resource.id") productAttributesResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.attributes.resource.url") productAttributesResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.attributes.resource.link") productSupplierResourceId.i = CkJsonObject::ckIntOf(jResp,"product.supplier.resource.id") productSupplierResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.supplier.resource.url") productSupplierResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.supplier.resource.link") productTagsResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.tags.resource.id") productTagsResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.tags.resource.url") productTagsResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.tags.resource.link") productVariantsResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.variants.resource.id") productVariantsResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.variants.resource.url") productVariantsResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.variants.resource.link") productMovementsResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.movements.resource.id") productMovementsResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.movements.resource.url") productMovementsResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.movements.resource.link") CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.