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
(Delphi DLL) 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
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; respStatusCode: Integer; id: Integer; sortOrder: Integer; name: PWideChar; j: Integer; count_j: Integer; productId: Integer; productCreatedAt: PWideChar; productUpdatedAt: PWideChar; productIsVisible: Boolean; productVisibility: PWideChar; productHasMatrix: Boolean; productData01: PWideChar; productData02: PWideChar; productData03: PWideChar; productUrl: PWideChar; productTitle: PWideChar; productFulltitle: PWideChar; productDescription: PWideChar; productContent: PWideChar; productSetId: Integer; productSetCreatedAt: PWideChar; productSetUpdatedAt: PWideChar; productSetName: PWideChar; productBrandResourceId: Integer; productBrandResourceUrl: PWideChar; productBrandResourceLink: PWideChar; productCategoriesResourceId: Boolean; productCategoriesResourceUrl: PWideChar; productCategoriesResourceLink: PWideChar; productDeliverydateResourceId: Integer; productDeliverydateResourceUrl: PWideChar; productDeliverydateResourceLink: PWideChar; productImageCreatedAt: PWideChar; productImageUpdatedAt: PWideChar; productImageExtension: PWideChar; productImageSize: Integer; productImageTitle: PWideChar; productImageThumb: PWideChar; productImageSrc: PWideChar; productImagesResourceId: Boolean; productImagesResourceUrl: PWideChar; productImagesResourceLink: PWideChar; productRelationsResourceId: Boolean; productRelationsResourceUrl: PWideChar; productRelationsResourceLink: PWideChar; productMetafieldsResourceId: Boolean; productMetafieldsResourceUrl: PWideChar; productMetafieldsResourceLink: PWideChar; productReviewsResourceId: Boolean; productReviewsResourceUrl: PWideChar; productReviewsResourceLink: PWideChar; productType: Boolean; productAttributesResourceId: Boolean; productAttributesResourceUrl: PWideChar; productAttributesResourceLink: PWideChar; productSupplierResourceId: Integer; productSupplierResourceUrl: PWideChar; productSupplierResourceLink: PWideChar; productTagsResourceId: Boolean; productTagsResourceUrl: PWideChar; productTagsResourceLink: PWideChar; productVariantsResourceId: Boolean; productVariantsResourceUrl: PWideChar; productVariantsResourceLink: PWideChar; productMovementsResourceId: Boolean; productMovementsResourceUrl: PWideChar; productMovementsResourceLink: PWideChar; i: Integer; count_i: Integer; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http := CkHttp_Create(); // 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_putLogin(http,'API_KEY'); CkHttp_putPassword(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 := CkStringBuilder_Create(); success := CkHttp_QuickGetSb(http,'https://api.webshopapp.com/en/products.json',sbResponseBody); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttp_getLastStatus(http); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttp__lastHeader(http)); Memo1.Lines.Add('Failed.'); Exit; end; // 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 productId := CkJsonObject_IntOf(jResp,'product.id'); productCreatedAt := CkJsonObject__stringOf(jResp,'product.createdAt'); productUpdatedAt := CkJsonObject__stringOf(jResp,'product.updatedAt'); productIsVisible := CkJsonObject_BoolOf(jResp,'product.isVisible'); productVisibility := CkJsonObject__stringOf(jResp,'product.visibility'); productHasMatrix := CkJsonObject_BoolOf(jResp,'product.hasMatrix'); productData01 := CkJsonObject__stringOf(jResp,'product.data01'); productData02 := CkJsonObject__stringOf(jResp,'product.data02'); productData03 := CkJsonObject__stringOf(jResp,'product.data03'); productUrl := CkJsonObject__stringOf(jResp,'product.url'); productTitle := CkJsonObject__stringOf(jResp,'product.title'); productFulltitle := CkJsonObject__stringOf(jResp,'product.fulltitle'); productDescription := CkJsonObject__stringOf(jResp,'product.description'); productContent := CkJsonObject__stringOf(jResp,'product.content'); productSetId := CkJsonObject_IntOf(jResp,'product.set.id'); productSetCreatedAt := CkJsonObject__stringOf(jResp,'product.set.createdAt'); productSetUpdatedAt := CkJsonObject__stringOf(jResp,'product.set.updatedAt'); productSetName := CkJsonObject__stringOf(jResp,'product.set.name'); productBrandResourceId := CkJsonObject_IntOf(jResp,'product.brand.resource.id'); productBrandResourceUrl := CkJsonObject__stringOf(jResp,'product.brand.resource.url'); productBrandResourceLink := CkJsonObject__stringOf(jResp,'product.brand.resource.link'); productCategoriesResourceId := CkJsonObject_BoolOf(jResp,'product.categories.resource.id'); productCategoriesResourceUrl := CkJsonObject__stringOf(jResp,'product.categories.resource.url'); productCategoriesResourceLink := CkJsonObject__stringOf(jResp,'product.categories.resource.link'); productDeliverydateResourceId := CkJsonObject_IntOf(jResp,'product.deliverydate.resource.id'); productDeliverydateResourceUrl := CkJsonObject__stringOf(jResp,'product.deliverydate.resource.url'); productDeliverydateResourceLink := CkJsonObject__stringOf(jResp,'product.deliverydate.resource.link'); productImageCreatedAt := CkJsonObject__stringOf(jResp,'product.image.createdAt'); productImageUpdatedAt := CkJsonObject__stringOf(jResp,'product.image.updatedAt'); productImageExtension := CkJsonObject__stringOf(jResp,'product.image.extension'); productImageSize := CkJsonObject_IntOf(jResp,'product.image.size'); productImageTitle := CkJsonObject__stringOf(jResp,'product.image.title'); productImageThumb := CkJsonObject__stringOf(jResp,'product.image.thumb'); productImageSrc := CkJsonObject__stringOf(jResp,'product.image.src'); productImagesResourceId := CkJsonObject_BoolOf(jResp,'product.images.resource.id'); productImagesResourceUrl := CkJsonObject__stringOf(jResp,'product.images.resource.url'); productImagesResourceLink := CkJsonObject__stringOf(jResp,'product.images.resource.link'); productRelationsResourceId := CkJsonObject_BoolOf(jResp,'product.relations.resource.id'); productRelationsResourceUrl := CkJsonObject__stringOf(jResp,'product.relations.resource.url'); productRelationsResourceLink := CkJsonObject__stringOf(jResp,'product.relations.resource.link'); productMetafieldsResourceId := CkJsonObject_BoolOf(jResp,'product.metafields.resource.id'); productMetafieldsResourceUrl := CkJsonObject__stringOf(jResp,'product.metafields.resource.url'); productMetafieldsResourceLink := CkJsonObject__stringOf(jResp,'product.metafields.resource.link'); productReviewsResourceId := CkJsonObject_BoolOf(jResp,'product.reviews.resource.id'); productReviewsResourceUrl := CkJsonObject__stringOf(jResp,'product.reviews.resource.url'); productReviewsResourceLink := CkJsonObject__stringOf(jResp,'product.reviews.resource.link'); productType := CkJsonObject_BoolOf(jResp,'product.type'); productAttributesResourceId := CkJsonObject_BoolOf(jResp,'product.attributes.resource.id'); productAttributesResourceUrl := CkJsonObject__stringOf(jResp,'product.attributes.resource.url'); productAttributesResourceLink := CkJsonObject__stringOf(jResp,'product.attributes.resource.link'); productSupplierResourceId := CkJsonObject_IntOf(jResp,'product.supplier.resource.id'); productSupplierResourceUrl := CkJsonObject__stringOf(jResp,'product.supplier.resource.url'); productSupplierResourceLink := CkJsonObject__stringOf(jResp,'product.supplier.resource.link'); productTagsResourceId := CkJsonObject_BoolOf(jResp,'product.tags.resource.id'); productTagsResourceUrl := CkJsonObject__stringOf(jResp,'product.tags.resource.url'); productTagsResourceLink := CkJsonObject__stringOf(jResp,'product.tags.resource.link'); productVariantsResourceId := CkJsonObject_BoolOf(jResp,'product.variants.resource.id'); productVariantsResourceUrl := CkJsonObject__stringOf(jResp,'product.variants.resource.url'); productVariantsResourceLink := CkJsonObject__stringOf(jResp,'product.variants.resource.link'); productMovementsResourceId := CkJsonObject_BoolOf(jResp,'product.movements.resource.id'); productMovementsResourceUrl := CkJsonObject__stringOf(jResp,'product.movements.resource.url'); productMovementsResourceLink := CkJsonObject__stringOf(jResp,'product.movements.resource.link'); i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'product.set.options'); while i < count_i do begin CkJsonObject_putI(jResp,i); id := CkJsonObject_IntOf(jResp,'product.set.options[i].id'); sortOrder := CkJsonObject_IntOf(jResp,'product.set.options[i].sortOrder'); name := CkJsonObject__stringOf(jResp,'product.set.options[i].name'); j := 0; count_j := CkJsonObject_SizeOfArray(jResp,'product.set.options[i].values'); while j < count_j do begin CkJsonObject_putJ(jResp,j); id := CkJsonObject_IntOf(jResp,'product.set.options[i].values[j].id'); sortOrder := CkJsonObject_IntOf(jResp,'product.set.options[i].values[j].sortOrder'); name := CkJsonObject__stringOf(jResp,'product.set.options[i].values[j].name'); j := j + 1; end; i := i + 1; end; CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.