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) 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
IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonArray.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkDtObj.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://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::setCkBasicAuth(http, 1) CkHttp::setCkLogin(http, "consumer_key") CkHttp::setCkPassword(http, "consumer_secret") sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckQuickGetSb(http,"https://example.com/wp-json/wc/v3/products",sbResponseBody) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf jarrResp.i = CkJsonArray::ckCreate() If jarrResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonArray::ckLoadSb(jarrResp,sbResponseBody) CkJsonArray::setCkEmitCompact(jarrResp, 0) Debug "Response Body:" Debug CkJsonArray::ckEmit(jarrResp) 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) CkJsonArray::ckDispose(jarrResp) ProcedureReturn EndIf ; 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.i = CkDtObj::ckCreate() If date_created.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_created_gmt.i = CkDtObj::ckCreate() If date_created_gmt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_modified.i = CkDtObj::ckCreate() If date_modified.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_modified_gmt.i = CkDtObj::ckCreate() If date_modified_gmt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_on_sale_from.i = CkDtObj::ckCreate() If date_on_sale_from.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_on_sale_from_gmt.i = CkDtObj::ckCreate() If date_on_sale_from_gmt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_on_sale_to.i = CkDtObj::ckCreate() If date_on_sale_to.i = 0 Debug "Failed to create object." ProcedureReturn EndIf date_on_sale_to_gmt.i = CkDtObj::ckCreate() If date_on_sale_to_gmt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf json.i id.i name.s slug.s permalink.s v_type.s status.s featured.i catalog_visibility.s description.s short_description.s sku.s price.s regular_price.s sale_price.s price_html.s on_sale.i purchasable.i total_sales.i v_virtual.i downloadable.i download_limit.i download_expiry.i external_url.s button_text.s tax_status.s tax_class.s manage_stock.i stock_quantity.s stock_status.s backorders.s backorders_allowed.i backordered.i sold_individually.i weight.s dimensionsLength.s dimensionsWidth.s dimensionsHeight.s shipping_required.i shipping_taxable.i shipping_class.s shipping_class_id.i reviews_allowed.i average_rating.s rating_count.i parent_id.i purchase_note.s menu_order.i j.i count_j.i intVal.i src.s alt.s position.i visible.i variation.i k.i count_k.i strVal.s v_option.s href.s i.i = 0 count_i.i = CkJsonArray::ckSize(jarrResp) While i < count_i json = CkJsonArray::ckObjectAt(jarrResp,i) id = CkJsonObject::ckIntOf(json,"id") name = CkJsonObject::ckStringOf(json,"name") slug = CkJsonObject::ckStringOf(json,"slug") permalink = CkJsonObject::ckStringOf(json,"permalink") CkJsonObject::ckDtOf(json,"date_created",0,date_created) CkJsonObject::ckDtOf(json,"date_created_gmt",0,date_created_gmt) CkJsonObject::ckDtOf(json,"date_modified",0,date_modified) CkJsonObject::ckDtOf(json,"date_modified_gmt",0,date_modified_gmt) v_type = CkJsonObject::ckStringOf(json,"type") status = CkJsonObject::ckStringOf(json,"status") featured = CkJsonObject::ckBoolOf(json,"featured") catalog_visibility = CkJsonObject::ckStringOf(json,"catalog_visibility") description = CkJsonObject::ckStringOf(json,"description") short_description = CkJsonObject::ckStringOf(json,"short_description") sku = CkJsonObject::ckStringOf(json,"sku") price = CkJsonObject::ckStringOf(json,"price") regular_price = CkJsonObject::ckStringOf(json,"regular_price") sale_price = CkJsonObject::ckStringOf(json,"sale_price") CkJsonObject::ckDtOf(json,"date_on_sale_from",0,date_on_sale_from) CkJsonObject::ckDtOf(json,"date_on_sale_from_gmt",0,date_on_sale_from_gmt) CkJsonObject::ckDtOf(json,"date_on_sale_to",0,date_on_sale_to) CkJsonObject::ckDtOf(json,"date_on_sale_to_gmt",0,date_on_sale_to_gmt) price_html = CkJsonObject::ckStringOf(json,"price_html") on_sale = CkJsonObject::ckBoolOf(json,"on_sale") purchasable = CkJsonObject::ckBoolOf(json,"purchasable") total_sales = CkJsonObject::ckIntOf(json,"total_sales") v_virtual = CkJsonObject::ckBoolOf(json,"virtual") downloadable = CkJsonObject::ckBoolOf(json,"downloadable") download_limit = CkJsonObject::ckIntOf(json,"download_limit") download_expiry = CkJsonObject::ckIntOf(json,"download_expiry") external_url = CkJsonObject::ckStringOf(json,"external_url") button_text = CkJsonObject::ckStringOf(json,"button_text") tax_status = CkJsonObject::ckStringOf(json,"tax_status") tax_class = CkJsonObject::ckStringOf(json,"tax_class") manage_stock = CkJsonObject::ckBoolOf(json,"manage_stock") stock_quantity = CkJsonObject::ckStringOf(json,"stock_quantity") stock_status = CkJsonObject::ckStringOf(json,"stock_status") backorders = CkJsonObject::ckStringOf(json,"backorders") backorders_allowed = CkJsonObject::ckBoolOf(json,"backorders_allowed") backordered = CkJsonObject::ckBoolOf(json,"backordered") sold_individually = CkJsonObject::ckBoolOf(json,"sold_individually") weight = CkJsonObject::ckStringOf(json,"weight") dimensionsLength = CkJsonObject::ckStringOf(json,"dimensions.length") dimensionsWidth = CkJsonObject::ckStringOf(json,"dimensions.width") dimensionsHeight = CkJsonObject::ckStringOf(json,"dimensions.height") shipping_required = CkJsonObject::ckBoolOf(json,"shipping_required") shipping_taxable = CkJsonObject::ckBoolOf(json,"shipping_taxable") shipping_class = CkJsonObject::ckStringOf(json,"shipping_class") shipping_class_id = CkJsonObject::ckIntOf(json,"shipping_class_id") reviews_allowed = CkJsonObject::ckBoolOf(json,"reviews_allowed") average_rating = CkJsonObject::ckStringOf(json,"average_rating") rating_count = CkJsonObject::ckIntOf(json,"rating_count") parent_id = CkJsonObject::ckIntOf(json,"parent_id") purchase_note = CkJsonObject::ckStringOf(json,"purchase_note") menu_order = CkJsonObject::ckIntOf(json,"menu_order") j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"downloads") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"related_ids") While j < count_j CkJsonObject::setCkJ(json, j) intVal = CkJsonObject::ckIntOf(json,"related_ids[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"upsell_ids") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"cross_sell_ids") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"categories") While j < count_j CkJsonObject::setCkJ(json, j) id = CkJsonObject::ckIntOf(json,"categories[j].id") name = CkJsonObject::ckStringOf(json,"categories[j].name") slug = CkJsonObject::ckStringOf(json,"categories[j].slug") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"tags") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"images") While j < count_j CkJsonObject::setCkJ(json, j) id = CkJsonObject::ckIntOf(json,"images[j].id") CkJsonObject::ckDtOf(json,"images[j].date_created",0,date_created) CkJsonObject::ckDtOf(json,"images[j].date_created_gmt",0,date_created_gmt) CkJsonObject::ckDtOf(json,"images[j].date_modified",0,date_modified) CkJsonObject::ckDtOf(json,"images[j].date_modified_gmt",0,date_modified_gmt) src = CkJsonObject::ckStringOf(json,"images[j].src") name = CkJsonObject::ckStringOf(json,"images[j].name") alt = CkJsonObject::ckStringOf(json,"images[j].alt") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"attributes") While j < count_j CkJsonObject::setCkJ(json, j) id = CkJsonObject::ckIntOf(json,"attributes[j].id") name = CkJsonObject::ckStringOf(json,"attributes[j].name") position = CkJsonObject::ckIntOf(json,"attributes[j].position") visible = CkJsonObject::ckBoolOf(json,"attributes[j].visible") variation = CkJsonObject::ckBoolOf(json,"attributes[j].variation") k = 0 count_k = CkJsonObject::ckSizeOfArray(json,"attributes[j].options") While k < count_k CkJsonObject::setCkK(json, k) strVal = CkJsonObject::ckStringOf(json,"attributes[j].options[k]") k = k + 1 Wend j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"default_attributes") While j < count_j CkJsonObject::setCkJ(json, j) id = CkJsonObject::ckIntOf(json,"default_attributes[j].id") name = CkJsonObject::ckStringOf(json,"default_attributes[j].name") v_option = CkJsonObject::ckStringOf(json,"default_attributes[j].option") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"variations") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"grouped_products") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"meta_data") While j < count_j CkJsonObject::setCkJ(json, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"_links.self") While j < count_j CkJsonObject::setCkJ(json, j) href = CkJsonObject::ckStringOf(json,"_links.self[j].href") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"_links.collection") While j < count_j CkJsonObject::setCkJ(json, j) href = CkJsonObject::ckStringOf(json,"_links.collection[j].href") j = j + 1 Wend CkJsonObject::ckDispose(json) i = i + 1 Wend CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonArray::ckDispose(jarrResp) CkDtObj::ckDispose(date_created) CkDtObj::ckDispose(date_created_gmt) CkDtObj::ckDispose(date_modified) CkDtObj::ckDispose(date_modified_gmt) CkDtObj::ckDispose(date_on_sale_from) CkDtObj::ckDispose(date_on_sale_from_gmt) CkDtObj::ckDispose(date_on_sale_to) CkDtObj::ckDispose(date_on_sale_to_gmt) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.