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
(Tcl) 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
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] # 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_put_BasicAuth $http 1 CkHttp_put_Login $http "consumer_key" CkHttp_put_Password $http "consumer_secret" set sbResponseBody [new_CkStringBuilder] set success [CkHttp_QuickGetSb $http "https://example.com/wp-json/wc/v3/products" $sbResponseBody] if {$success == 0} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkStringBuilder $sbResponseBody exit } set jarrResp [new_CkJsonArray] CkJsonArray_LoadSb $jarrResp $sbResponseBody CkJsonArray_put_EmitCompact $jarrResp 0 puts "Response Body:" puts [CkJsonArray_emit $jarrResp] set respStatusCode [CkHttp_get_LastStatus $http] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttp_lastHeader $http] puts "Failed." delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonArray $jarrResp exit } # 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 set date_created [new_CkDtObj] set date_created_gmt [new_CkDtObj] set date_modified [new_CkDtObj] set date_modified_gmt [new_CkDtObj] set date_on_sale_from [new_CkDtObj] set date_on_sale_from_gmt [new_CkDtObj] set date_on_sale_to [new_CkDtObj] set date_on_sale_to_gmt [new_CkDtObj] # json is a CkJsonObject set i 0 set count_i [CkJsonArray_get_Size $jarrResp] while {$i < $count_i} { set json [CkJsonArray_ObjectAt $jarrResp $i] set id [CkJsonObject_IntOf $json "id"] set name [CkJsonObject_stringOf $json "name"] set slug [CkJsonObject_stringOf $json "slug"] set permalink [CkJsonObject_stringOf $json "permalink"] CkJsonObject_DtOf $json "date_created" 0 $date_created CkJsonObject_DtOf $json "date_created_gmt" 0 $date_created_gmt CkJsonObject_DtOf $json "date_modified" 0 $date_modified CkJsonObject_DtOf $json "date_modified_gmt" 0 $date_modified_gmt set v_type [CkJsonObject_stringOf $json "type"] set status [CkJsonObject_stringOf $json "status"] set featured [CkJsonObject_BoolOf $json "featured"] set catalog_visibility [CkJsonObject_stringOf $json "catalog_visibility"] set description [CkJsonObject_stringOf $json "description"] set short_description [CkJsonObject_stringOf $json "short_description"] set sku [CkJsonObject_stringOf $json "sku"] set price [CkJsonObject_stringOf $json "price"] set regular_price [CkJsonObject_stringOf $json "regular_price"] set sale_price [CkJsonObject_stringOf $json "sale_price"] CkJsonObject_DtOf $json "date_on_sale_from" 0 $date_on_sale_from CkJsonObject_DtOf $json "date_on_sale_from_gmt" 0 $date_on_sale_from_gmt CkJsonObject_DtOf $json "date_on_sale_to" 0 $date_on_sale_to CkJsonObject_DtOf $json "date_on_sale_to_gmt" 0 $date_on_sale_to_gmt set price_html [CkJsonObject_stringOf $json "price_html"] set on_sale [CkJsonObject_BoolOf $json "on_sale"] set purchasable [CkJsonObject_BoolOf $json "purchasable"] set total_sales [CkJsonObject_IntOf $json "total_sales"] set v_virtual [CkJsonObject_BoolOf $json "virtual"] set downloadable [CkJsonObject_BoolOf $json "downloadable"] set download_limit [CkJsonObject_IntOf $json "download_limit"] set download_expiry [CkJsonObject_IntOf $json "download_expiry"] set external_url [CkJsonObject_stringOf $json "external_url"] set button_text [CkJsonObject_stringOf $json "button_text"] set tax_status [CkJsonObject_stringOf $json "tax_status"] set tax_class [CkJsonObject_stringOf $json "tax_class"] set manage_stock [CkJsonObject_BoolOf $json "manage_stock"] set stock_quantity [CkJsonObject_stringOf $json "stock_quantity"] set stock_status [CkJsonObject_stringOf $json "stock_status"] set backorders [CkJsonObject_stringOf $json "backorders"] set backorders_allowed [CkJsonObject_BoolOf $json "backorders_allowed"] set backordered [CkJsonObject_BoolOf $json "backordered"] set sold_individually [CkJsonObject_BoolOf $json "sold_individually"] set weight [CkJsonObject_stringOf $json "weight"] set dimensionsLength [CkJsonObject_stringOf $json "dimensions.length"] set dimensionsWidth [CkJsonObject_stringOf $json "dimensions.width"] set dimensionsHeight [CkJsonObject_stringOf $json "dimensions.height"] set shipping_required [CkJsonObject_BoolOf $json "shipping_required"] set shipping_taxable [CkJsonObject_BoolOf $json "shipping_taxable"] set shipping_class [CkJsonObject_stringOf $json "shipping_class"] set shipping_class_id [CkJsonObject_IntOf $json "shipping_class_id"] set reviews_allowed [CkJsonObject_BoolOf $json "reviews_allowed"] set average_rating [CkJsonObject_stringOf $json "average_rating"] set rating_count [CkJsonObject_IntOf $json "rating_count"] set parent_id [CkJsonObject_IntOf $json "parent_id"] set purchase_note [CkJsonObject_stringOf $json "purchase_note"] set menu_order [CkJsonObject_IntOf $json "menu_order"] set j 0 set count_j [CkJsonObject_SizeOfArray $json "downloads"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "related_ids"] while {$j < $count_j} { CkJsonObject_put_J $json $j set intVal [CkJsonObject_IntOf $json "related_ids[j]"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "upsell_ids"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "cross_sell_ids"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "categories"] while {$j < $count_j} { CkJsonObject_put_J $json $j set id [CkJsonObject_IntOf $json "categories[j].id"] set name [CkJsonObject_stringOf $json "categories[j].name"] set slug [CkJsonObject_stringOf $json "categories[j].slug"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "tags"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "images"] while {$j < $count_j} { CkJsonObject_put_J $json $j set id [CkJsonObject_IntOf $json "images[j].id"] CkJsonObject_DtOf $json "images[j].date_created" 0 $date_created CkJsonObject_DtOf $json "images[j].date_created_gmt" 0 $date_created_gmt CkJsonObject_DtOf $json "images[j].date_modified" 0 $date_modified CkJsonObject_DtOf $json "images[j].date_modified_gmt" 0 $date_modified_gmt set src [CkJsonObject_stringOf $json "images[j].src"] set name [CkJsonObject_stringOf $json "images[j].name"] set alt [CkJsonObject_stringOf $json "images[j].alt"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "attributes"] while {$j < $count_j} { CkJsonObject_put_J $json $j set id [CkJsonObject_IntOf $json "attributes[j].id"] set name [CkJsonObject_stringOf $json "attributes[j].name"] set position [CkJsonObject_IntOf $json "attributes[j].position"] set visible [CkJsonObject_BoolOf $json "attributes[j].visible"] set variation [CkJsonObject_BoolOf $json "attributes[j].variation"] set k 0 set count_k [CkJsonObject_SizeOfArray $json "attributes[j].options"] while {$k < $count_k} { CkJsonObject_put_K $json $k set strVal [CkJsonObject_stringOf $json "attributes[j].options[k]"] set k [expr $k + 1] } set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "default_attributes"] while {$j < $count_j} { CkJsonObject_put_J $json $j set id [CkJsonObject_IntOf $json "default_attributes[j].id"] set name [CkJsonObject_stringOf $json "default_attributes[j].name"] set v_option [CkJsonObject_stringOf $json "default_attributes[j].option"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "variations"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "grouped_products"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "meta_data"] while {$j < $count_j} { CkJsonObject_put_J $json $j set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.self"] while {$j < $count_j} { CkJsonObject_put_J $json $j set href [CkJsonObject_stringOf $json "_links.self[j].href"] set j [expr $j + 1] } set j 0 set count_j [CkJsonObject_SizeOfArray $json "_links.collection"] while {$j < $count_j} { CkJsonObject_put_J $json $j set href [CkJsonObject_stringOf $json "_links.collection[j].href"] set j [expr $j + 1] } delete_CkJsonObject $json set i [expr $i + 1] } delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonArray $jarrResp delete_CkDtObj $date_created delete_CkDtObj $date_created_gmt delete_CkDtObj $date_modified delete_CkDtObj $date_modified_gmt delete_CkDtObj $date_on_sale_from delete_CkDtObj $date_on_sale_from_gmt delete_CkDtObj $date_on_sale_to delete_CkDtObj $date_on_sale_to_gmt |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.