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) WooCommerce List All ProductsSee more WooCommerce ExamplesGets WooCommerce product information in JSON format. For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#list-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, DtObj, JsonArray, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; success: Boolean; sbResponseBody: HCkStringBuilder; jarrResp: HCkJsonArray; respStatusCode: Integer; date_created: HCkDtObj; date_created_gmt: HCkDtObj; date_modified: HCkDtObj; date_modified_gmt: HCkDtObj; date_on_sale_from: HCkDtObj; date_on_sale_from_gmt: HCkDtObj; date_on_sale_to: HCkDtObj; date_on_sale_to_gmt: HCkDtObj; json: HCkJsonObject; id: Integer; name: PWideChar; slug: PWideChar; permalink: PWideChar; v_type: PWideChar; status: PWideChar; featured: Boolean; catalog_visibility: PWideChar; description: PWideChar; short_description: PWideChar; sku: PWideChar; price: PWideChar; regular_price: PWideChar; sale_price: PWideChar; price_html: PWideChar; on_sale: Boolean; purchasable: Boolean; total_sales: Integer; v_virtual: Boolean; downloadable: Boolean; download_limit: Integer; download_expiry: Integer; external_url: PWideChar; button_text: PWideChar; tax_status: PWideChar; tax_class: PWideChar; manage_stock: Boolean; stock_quantity: PWideChar; stock_status: PWideChar; backorders: PWideChar; backorders_allowed: Boolean; backordered: Boolean; sold_individually: Boolean; weight: PWideChar; dimensionsLength: PWideChar; dimensionsWidth: PWideChar; dimensionsHeight: PWideChar; shipping_required: Boolean; shipping_taxable: Boolean; shipping_class: PWideChar; shipping_class_id: Integer; reviews_allowed: Boolean; average_rating: PWideChar; rating_count: Integer; parent_id: Integer; purchase_note: PWideChar; menu_order: Integer; j: Integer; count_j: Integer; intVal: Integer; src: PWideChar; alt: PWideChar; position: Integer; visible: Boolean; variation: Boolean; k: Integer; count_k: Integer; strVal: PWideChar; v_option: PWideChar; href: 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://example.com/wp-json/wc/v3/products \ // -u consumer_key:consumer_secret // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code CkHttp_putBasicAuth(http,True); CkHttp_putLogin(http,'consumer_key'); CkHttp_putPassword(http,'consumer_secret'); sbResponseBody := CkStringBuilder_Create(); success := CkHttp_QuickGetSb(http,'https://example.com/wp-json/wc/v3/products',sbResponseBody); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; jarrResp := CkJsonArray_Create(); CkJsonArray_LoadSb(jarrResp,sbResponseBody); CkJsonArray_putEmitCompact(jarrResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonArray__emit(jarrResp)); 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) // [ // { // "id": 799, // "name": "Ship Your Idea", // "slug": "ship-your-idea-22", // "permalink": "https://example.com/product/ship-your-idea-22/", // "date_created": "2017-03-23T17:03:12", // "date_created_gmt": "2017-03-23T20:03:12", // "date_modified": "2017-03-23T17:03:12", // "date_modified_gmt": "2017-03-23T20:03:12", // "type": "variable", // "status": "publish", // "featured": false, // "catalog_visibility": "visible", // "description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n", // "short_description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>\n", // "sku": "", // "price": "", // "regular_price": "", // "sale_price": "", // "date_on_sale_from": null, // "date_on_sale_from_gmt": null, // "date_on_sale_to": null, // "date_on_sale_to_gmt": null, // "price_html": "", // "on_sale": false, // "purchasable": false, // "total_sales": 0, // "virtual": false, // "downloadable": false, // "downloads": [ // ], // "download_limit": -1, // "download_expiry": -1, // "external_url": "", // "button_text": "", // "tax_status": "taxable", // "tax_class": "", // "manage_stock": false, // "stock_quantity": null, // "stock_status": "instock", // "backorders": "no", // "backorders_allowed": false, // "backordered": false, // "sold_individually": false, // "weight": "", // "dimensions": { // "length": "", // "width": "", // "height": "" // }, // "shipping_required": true, // "shipping_taxable": true, // "shipping_class": "", // "shipping_class_id": 0, // "reviews_allowed": true, // "average_rating": "0.00", // "rating_count": 0, // "related_ids": [ // 31, // 22, // 369, // 414, // 56 // ], // "upsell_ids": [ // ], // "cross_sell_ids": [ // ], // "parent_id": 0, // "purchase_note": "", // "categories": [ // { // "id": 9, // "name": "Clothing", // "slug": "clothing" // }, // { // "id": 14, // "name": "T-shirts", // "slug": "t-shirts" // } // ], // "tags": [ // ], // "images": [ // { // "id": 795, // "date_created": "2017-03-23T14:03:08", // "date_created_gmt": "2017-03-23T20:03:08", // "date_modified": "2017-03-23T14:03:08", // "date_modified_gmt": "2017-03-23T20:03:08", // "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", // "name": "", // "alt": "" // }, // { // "id": 796, // "date_created": "2017-03-23T14:03:09", // "date_created_gmt": "2017-03-23T20:03:09", // "date_modified": "2017-03-23T14:03:09", // "date_modified_gmt": "2017-03-23T20:03:09", // "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", // "name": "", // "alt": "" // }, // { // "id": 797, // "date_created": "2017-03-23T14:03:10", // "date_created_gmt": "2017-03-23T20:03:10", // "date_modified": "2017-03-23T14:03:10", // "date_modified_gmt": "2017-03-23T20:03:10", // "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", // "name": "", // "alt": "" // }, // { // "id": 798, // "date_created": "2017-03-23T14:03:11", // "date_created_gmt": "2017-03-23T20:03:11", // "date_modified": "2017-03-23T14:03:11", // "date_modified_gmt": "2017-03-23T20:03:11", // "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", // "name": "", // "alt": "" // } // ], // "attributes": [ // { // "id": 6, // "name": "Color", // "position": 0, // "visible": false, // "variation": true, // "options": [ // "Black", // "Green" // ] // }, // { // "id": 0, // "name": "Size", // "position": 0, // "visible": true, // "variation": true, // "options": [ // "S", // "M" // ] // } // ], // "default_attributes": [ // ], // "variations": [ // ], // "grouped_products": [ // ], // "menu_order": 0, // "meta_data": [ // ], // "_links": { // "self": [ // { // "href": "https://example.com/wp-json/wc/v3/products/799" // } // ], // "collection": [ // { // "href": "https://example.com/wp-json/wc/v3/products" // } // ] // } // }, // { // "id": 794, // "name": "Premium Quality", // "slug": "premium-quality-19", // "permalink": "https://example.com/product/premium-quality-19/", // "date_created": "2017-03-23T17:01:14", // "date_created_gmt": "2017-03-23T20:01:14", // "date_modified": "2017-03-23T17:01:14", // "date_modified_gmt": "2017-03-23T20:01:14", // "type": "simple", // "status": "publish", // "featured": false, // "catalog_visibility": "visible", // "description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n", // "short_description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>\n", // "sku": "", // "price": "21.99", // "regular_price": "21.99", // "sale_price": "", // "date_on_sale_from": null, // "date_on_sale_from_gmt": null, // "date_on_sale_to": null, // "date_on_sale_to_gmt": null, // "price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">$</span>21.99</span>", // "on_sale": false, // "purchasable": true, // "total_sales": 0, // "virtual": false, // "downloadable": false, // "downloads": [ // ], // "download_limit": -1, // "download_expiry": -1, // "external_url": "", // "button_text": "", // "tax_status": "taxable", // "tax_class": "", // "manage_stock": false, // "stock_quantity": null, // "stock_status": "instock", // "backorders": "no", // "backorders_allowed": false, // "backordered": false, // "sold_individually": false, // "weight": "", // "dimensions": { // "length": "", // "width": "", // "height": "" // }, // "shipping_required": true, // "shipping_taxable": true, // "shipping_class": "", // "shipping_class_id": 0, // "reviews_allowed": true, // "average_rating": "0.00", // "rating_count": 0, // "related_ids": [ // 463, // 47, // 31, // 387, // 458 // ], // "upsell_ids": [ // ], // "cross_sell_ids": [ // ], // "parent_id": 0, // "purchase_note": "", // "categories": [ // { // "id": 9, // "name": "Clothing", // "slug": "clothing" // }, // { // "id": 14, // "name": "T-shirts", // "slug": "t-shirts" // } // ], // "tags": [ // ], // "images": [ // { // "id": 792, // "date_created": "2017-03-23T14:01:13", // "date_created_gmt": "2017-03-23T20:01:13", // "date_modified": "2017-03-23T14:01:13", // "date_modified_gmt": "2017-03-23T20:01:13", // "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", // "name": "", // "alt": "" // }, // { // "id": 793, // "date_created": "2017-03-23T14:01:14", // "date_created_gmt": "2017-03-23T20:01:14", // "date_modified": "2017-03-23T14:01:14", // "date_modified_gmt": "2017-03-23T20:01:14", // "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", // "name": "", // "alt": "" // } // ], // "attributes": [ // ], // "default_attributes": [ // { // "id": 6, // "name": "Color", // "option": "black" // }, // { // "id": 0, // "name": "Size", // "option": "S" // } // ], // "variations": [ // ], // "grouped_products": [ // ], // "menu_order": 0, // "meta_data": [ // ], // "_links": { // "self": [ // { // "href": "https://example.com/wp-json/wc/v3/products/794" // } // ], // "collection": [ // { // "href": "https://example.com/wp-json/wc/v3/products" // } // ] // } // } // ] // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON date_created := CkDtObj_Create(); date_created_gmt := CkDtObj_Create(); date_modified := CkDtObj_Create(); date_modified_gmt := CkDtObj_Create(); date_on_sale_from := CkDtObj_Create(); date_on_sale_from_gmt := CkDtObj_Create(); date_on_sale_to := CkDtObj_Create(); date_on_sale_to_gmt := CkDtObj_Create(); i := 0; count_i := CkJsonArray_getSize(jarrResp); while i < count_i do begin json := CkJsonArray_ObjectAt(jarrResp,i); id := CkJsonObject_IntOf(json,'id'); name := CkJsonObject__stringOf(json,'name'); slug := CkJsonObject__stringOf(json,'slug'); permalink := CkJsonObject__stringOf(json,'permalink'); CkJsonObject_DtOf(json,'date_created',False,date_created); CkJsonObject_DtOf(json,'date_created_gmt',False,date_created_gmt); CkJsonObject_DtOf(json,'date_modified',False,date_modified); CkJsonObject_DtOf(json,'date_modified_gmt',False,date_modified_gmt); v_type := CkJsonObject__stringOf(json,'type'); status := CkJsonObject__stringOf(json,'status'); featured := CkJsonObject_BoolOf(json,'featured'); catalog_visibility := CkJsonObject__stringOf(json,'catalog_visibility'); description := CkJsonObject__stringOf(json,'description'); short_description := CkJsonObject__stringOf(json,'short_description'); sku := CkJsonObject__stringOf(json,'sku'); price := CkJsonObject__stringOf(json,'price'); regular_price := CkJsonObject__stringOf(json,'regular_price'); sale_price := CkJsonObject__stringOf(json,'sale_price'); CkJsonObject_DtOf(json,'date_on_sale_from',False,date_on_sale_from); CkJsonObject_DtOf(json,'date_on_sale_from_gmt',False,date_on_sale_from_gmt); CkJsonObject_DtOf(json,'date_on_sale_to',False,date_on_sale_to); CkJsonObject_DtOf(json,'date_on_sale_to_gmt',False,date_on_sale_to_gmt); price_html := CkJsonObject__stringOf(json,'price_html'); on_sale := CkJsonObject_BoolOf(json,'on_sale'); purchasable := CkJsonObject_BoolOf(json,'purchasable'); total_sales := CkJsonObject_IntOf(json,'total_sales'); v_virtual := CkJsonObject_BoolOf(json,'virtual'); downloadable := CkJsonObject_BoolOf(json,'downloadable'); download_limit := CkJsonObject_IntOf(json,'download_limit'); download_expiry := CkJsonObject_IntOf(json,'download_expiry'); external_url := CkJsonObject__stringOf(json,'external_url'); button_text := CkJsonObject__stringOf(json,'button_text'); tax_status := CkJsonObject__stringOf(json,'tax_status'); tax_class := CkJsonObject__stringOf(json,'tax_class'); manage_stock := CkJsonObject_BoolOf(json,'manage_stock'); stock_quantity := CkJsonObject__stringOf(json,'stock_quantity'); stock_status := CkJsonObject__stringOf(json,'stock_status'); backorders := CkJsonObject__stringOf(json,'backorders'); backorders_allowed := CkJsonObject_BoolOf(json,'backorders_allowed'); backordered := CkJsonObject_BoolOf(json,'backordered'); sold_individually := CkJsonObject_BoolOf(json,'sold_individually'); weight := CkJsonObject__stringOf(json,'weight'); dimensionsLength := CkJsonObject__stringOf(json,'dimensions.length'); dimensionsWidth := CkJsonObject__stringOf(json,'dimensions.width'); dimensionsHeight := CkJsonObject__stringOf(json,'dimensions.height'); shipping_required := CkJsonObject_BoolOf(json,'shipping_required'); shipping_taxable := CkJsonObject_BoolOf(json,'shipping_taxable'); shipping_class := CkJsonObject__stringOf(json,'shipping_class'); shipping_class_id := CkJsonObject_IntOf(json,'shipping_class_id'); reviews_allowed := CkJsonObject_BoolOf(json,'reviews_allowed'); average_rating := CkJsonObject__stringOf(json,'average_rating'); rating_count := CkJsonObject_IntOf(json,'rating_count'); parent_id := CkJsonObject_IntOf(json,'parent_id'); purchase_note := CkJsonObject__stringOf(json,'purchase_note'); menu_order := CkJsonObject_IntOf(json,'menu_order'); j := 0; count_j := CkJsonObject_SizeOfArray(json,'downloads'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'related_ids'); while j < count_j do begin CkJsonObject_putJ(json,j); intVal := CkJsonObject_IntOf(json,'related_ids[j]'); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'upsell_ids'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'cross_sell_ids'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'categories'); while j < count_j do begin CkJsonObject_putJ(json,j); id := CkJsonObject_IntOf(json,'categories[j].id'); name := CkJsonObject__stringOf(json,'categories[j].name'); slug := CkJsonObject__stringOf(json,'categories[j].slug'); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'tags'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'images'); while j < count_j do begin CkJsonObject_putJ(json,j); id := CkJsonObject_IntOf(json,'images[j].id'); CkJsonObject_DtOf(json,'images[j].date_created',False,date_created); CkJsonObject_DtOf(json,'images[j].date_created_gmt',False,date_created_gmt); CkJsonObject_DtOf(json,'images[j].date_modified',False,date_modified); CkJsonObject_DtOf(json,'images[j].date_modified_gmt',False,date_modified_gmt); src := CkJsonObject__stringOf(json,'images[j].src'); name := CkJsonObject__stringOf(json,'images[j].name'); alt := CkJsonObject__stringOf(json,'images[j].alt'); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'attributes'); while j < count_j do begin CkJsonObject_putJ(json,j); id := CkJsonObject_IntOf(json,'attributes[j].id'); name := CkJsonObject__stringOf(json,'attributes[j].name'); position := CkJsonObject_IntOf(json,'attributes[j].position'); visible := CkJsonObject_BoolOf(json,'attributes[j].visible'); variation := CkJsonObject_BoolOf(json,'attributes[j].variation'); k := 0; count_k := CkJsonObject_SizeOfArray(json,'attributes[j].options'); while k < count_k do begin CkJsonObject_putK(json,k); strVal := CkJsonObject__stringOf(json,'attributes[j].options[k]'); k := k + 1; end; j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'default_attributes'); while j < count_j do begin CkJsonObject_putJ(json,j); id := CkJsonObject_IntOf(json,'default_attributes[j].id'); name := CkJsonObject__stringOf(json,'default_attributes[j].name'); v_option := CkJsonObject__stringOf(json,'default_attributes[j].option'); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'variations'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'grouped_products'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'meta_data'); while j < count_j do begin CkJsonObject_putJ(json,j); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'_links.self'); while j < count_j do begin CkJsonObject_putJ(json,j); href := CkJsonObject__stringOf(json,'_links.self[j].href'); j := j + 1; end; j := 0; count_j := CkJsonObject_SizeOfArray(json,'_links.collection'); while j < count_j do begin CkJsonObject_putJ(json,j); href := CkJsonObject__stringOf(json,'_links.collection[j].href'); j := j + 1; end; CkJsonObject_Dispose(json); i := i + 1; end; CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonArray_Dispose(jarrResp); CkDtObj_Dispose(date_created); CkDtObj_Dispose(date_created_gmt); CkDtObj_Dispose(date_modified); CkDtObj_Dispose(date_modified_gmt); CkDtObj_Dispose(date_on_sale_from); CkDtObj_Dispose(date_on_sale_from_gmt); CkDtObj_Dispose(date_on_sale_to); CkDtObj_Dispose(date_on_sale_to_gmt); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.