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 - Get All ProductsRetrieve a list of all product objects from this shop. For more information, see https://developers.lightspeedhq.com/ecom/endpoints/product/#get-all-products
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 https://api.shoplightspeed.com/en/products.json \ ; -u {key}:{secret} ; 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 the correct cluster for your shop. Here are the choices: ; eu1 https://api.webshopapp.com/en/ ; us1 https://api.shoplightspeed.com/en/ sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckQuickGetSb(http,"https://api.webshopapp.com/en/products.json",sbResponseBody) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf 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 = CkHttp::ckLastStatus(http) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttp::ckLastHeader(http) Debug "Failed." CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "product": { ; "id": 20967267, ; "createdAt": "2019-05-28T15:25:46+00:00", ; "updatedAt": "2019-05-28T17:16:16+00:00", ; "isVisible": true, ; "visibility": "visible", ; "hasMatrix": false, ; "data01": "", ; "data02": "", ; "data03": "", ; "url": "lookin-sharp-tee", ; "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": { ; "id": 2785, ; "createdAt": "2019-05-28T15:32:12+00:00", ; "updatedAt": "2019-05-28T15:42:59+00:00", ; "name": "Shirts", ; "options": [ ; { ; "id": 4626, ; "sortOrder": 1, ; "name": "Size", ; "values": [ ; { ; "id": 14045, ; "sortOrder": 1, ; "name": "S" ; }, ; { ; "id": 14046, ; "sortOrder": 2, ; "name": "M" ; }, ; { ; "id": 14047, ; "sortOrder": 3, ; "name": "L" ; } ; ] ; } ; ] ; }, ; "brand": { ; "resource": { ; "id": 1171202, ; "url": "brands/1171202", ; "link": "https://api.shoplightspeed.com/us/brands/1171202.json" ; } ; }, ; "categories": { ; "resource": { ; "id": false, ; "url": "categories/products?product=20967267", ; "link": "https://api.shoplightspeed.com/us/categories/products.json?product=20967267" ; } ; }, ; "deliverydate": { ; "resource": { ; "id": 6488, ; "url": "deliverydates/6488", ; "link": "https://api.shoplightspeed.com/us/deliverydates/6488.json" ; } ; }, ; "image": { ; "createdAt": "2019-05-28T15:25:46+00:00", ; "updatedAt": "2019-05-28T15:25:46+00:00", ; "extension": "jpg", ; "size": 86649, ; "title": "17x35x-jcfk-88na-udwd-5hck-z63u-img-16-e0aa4f57-f4", ; "thumb": "https://cdn.shoplightspeed.com/shops/000001/files/14119398/50x50x2/17x35x-jcfk-88na-udwd-5hck-z63u-img-16-e0aa4f57-f4.jpg", ; "src": "https://cdn.shoplightspeed.com/shops/000001/files/14119398/17x35x-jcfk-88na-udwd-5hck-z63u-img-16-e0aa4f57-f4.jpg" ; }, ; "images": { ; "resource": { ; "id": false, ; "url": "products/20967267/images", ; "link": "https://api.shoplightspeed.com/us/products/20967267/images.json" ; } ; }, ; "relations": { ; "resource": { ; "id": false, ; "url": "products/20967267/relations", ; "link": "https://api.shoplightspeed.com/us/products/20967267/relations.json" ; } ; }, ; "metafields": { ; "resource": { ; "id": false, ; "url": "products/20967267/metafields", ; "link": "https://api.shoplightspeed.com/us/products/20967267/metafields.json" ; } ; }, ; "reviews": { ; "resource": { ; "id": false, ; "url": "reviews?product=20967267", ; "link": "https://api.shoplightspeed.com/us/reviews.json?product=20967267" ; } ; }, ; "type": false, ; "attributes": { ; "resource": { ; "id": false, ; "url": "products/20967267/attributes", ; "link": "https://api.shoplightspeed.com/us/products/20967267/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=20967267", ; "link": "https://api.shoplightspeed.com/us/tags/products.json?product=20967267" ; } ; }, ; "variants": { ; "resource": { ; "id": false, ; "url": "variants?product=20967267", ; "link": "https://api.shoplightspeed.com/us/variants.json?product=20967267" ; } ; }, ; "movements": { ; "resource": { ; "id": false, ; "url": "variants/movements?product=20967267", ; "link": "https://api.shoplightspeed.com/us/variants/movements.json?product=20967267" ; } ; } ; } ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON id.i sortOrder.i name.s j.i count_j.i 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") productSetId.i = CkJsonObject::ckIntOf(jResp,"product.set.id") productSetCreatedAt.s = CkJsonObject::ckStringOf(jResp,"product.set.createdAt") productSetUpdatedAt.s = CkJsonObject::ckStringOf(jResp,"product.set.updatedAt") productSetName.s = CkJsonObject::ckStringOf(jResp,"product.set.name") 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") productImageCreatedAt.s = CkJsonObject::ckStringOf(jResp,"product.image.createdAt") productImageUpdatedAt.s = CkJsonObject::ckStringOf(jResp,"product.image.updatedAt") productImageExtension.s = CkJsonObject::ckStringOf(jResp,"product.image.extension") productImageSize.i = CkJsonObject::ckIntOf(jResp,"product.image.size") productImageTitle.s = CkJsonObject::ckStringOf(jResp,"product.image.title") productImageThumb.s = CkJsonObject::ckStringOf(jResp,"product.image.thumb") productImageSrc.s = CkJsonObject::ckStringOf(jResp,"product.image.src") productImagesResourceId.i = CkJsonObject::ckBoolOf(jResp,"product.images.resource.id") productImagesResourceUrl.s = CkJsonObject::ckStringOf(jResp,"product.images.resource.url") productImagesResourceLink.s = CkJsonObject::ckStringOf(jResp,"product.images.resource.link") 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") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"product.set.options") While i < count_i CkJsonObject::setCkI(jResp, i) id = CkJsonObject::ckIntOf(jResp,"product.set.options[i].id") sortOrder = CkJsonObject::ckIntOf(jResp,"product.set.options[i].sortOrder") name = CkJsonObject::ckStringOf(jResp,"product.set.options[i].name") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"product.set.options[i].values") While j < count_j CkJsonObject::setCkJ(jResp, j) id = CkJsonObject::ckIntOf(jResp,"product.set.options[i].values[j].id") sortOrder = CkJsonObject::ckIntOf(jResp,"product.set.options[i].values[j].sortOrder") name = CkJsonObject::ckStringOf(jResp,"product.set.options[i].values[j].name") j = j + 1 Wend i = i + 1 Wend CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.