Visual FoxPro
Visual FoxPro
WooCommerce List All Products
See more WooCommerce Examples
Gets WooCommerce product information in JSON format.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loSbResponseBody
LOCAL loJarrResp
LOCAL lnRespStatusCode
LOCAL loDate_created
LOCAL loDate_created_gmt
LOCAL loDate_modified
LOCAL loDate_modified_gmt
LOCAL loDate_on_sale_from
LOCAL loDate_on_sale_from_gmt
LOCAL loDate_on_sale_to
LOCAL loDate_on_sale_to_gmt
LOCAL loJson
LOCAL lnId
LOCAL lcName
LOCAL lcSlug
LOCAL lcPermalink
LOCAL lcV_type
LOCAL lcStatus
LOCAL lnFeatured
LOCAL lcCatalog_visibility
LOCAL lcDescription
LOCAL lcShort_description
LOCAL lcSku
LOCAL lcPrice
LOCAL lcRegular_price
LOCAL lcSale_price
LOCAL lcPrice_html
LOCAL lnOn_sale
LOCAL lnPurchasable
LOCAL lnTotal_sales
LOCAL lnV_virtual
LOCAL lnDownloadable
LOCAL lnDownload_limit
LOCAL lnDownload_expiry
LOCAL lcExternal_url
LOCAL lcButton_text
LOCAL lcTax_status
LOCAL lcTax_class
LOCAL lnManage_stock
LOCAL lcStock_quantity
LOCAL lcStock_status
LOCAL lcBackorders
LOCAL lnBackorders_allowed
LOCAL lnBackordered
LOCAL lnSold_individually
LOCAL lcWeight
LOCAL lcDimensionsLength
LOCAL lcDimensionsWidth
LOCAL lcDimensionsHeight
LOCAL lnShipping_required
LOCAL lnShipping_taxable
LOCAL lcShipping_class
LOCAL lnShipping_class_id
LOCAL lnReviews_allowed
LOCAL lcAverage_rating
LOCAL lnRating_count
LOCAL lnParent_id
LOCAL lcPurchase_note
LOCAL lnMenu_order
LOCAL j
LOCAL lnCount_j
LOCAL lnIntVal
LOCAL lcSrc
LOCAL lcAlt
LOCAL lnPosition
LOCAL lnVisible
LOCAL lnVariation
LOCAL k
LOCAL lnCount_k
LOCAL lcStrVal
LOCAL lcV_option
LOCAL lcHref
LOCAL i
LOCAL lnCount_i
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
* 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
loHttp.BasicAuth = 1
loHttp.Login = "consumer_key"
loHttp.Password = "consumer_secret"
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://example.com/wp-json/wc/v3/products",loSbResponseBody)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loSbResponseBody
CANCEL
ENDIF
loJarrResp = CreateObject('Chilkat.JsonArray')
loJarrResp.LoadSb(loSbResponseBody)
loJarrResp.EmitCompact = 0
? "Response Body:"
? loJarrResp.Emit()
lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loHttp.LastHeader
? "Failed."
RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJarrResp
CANCEL
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
loDate_created = CreateObject('Chilkat.DtObj')
loDate_created_gmt = CreateObject('Chilkat.DtObj')
loDate_modified = CreateObject('Chilkat.DtObj')
loDate_modified_gmt = CreateObject('Chilkat.DtObj')
loDate_on_sale_from = CreateObject('Chilkat.DtObj')
loDate_on_sale_from_gmt = CreateObject('Chilkat.DtObj')
loDate_on_sale_to = CreateObject('Chilkat.DtObj')
loDate_on_sale_to_gmt = CreateObject('Chilkat.DtObj')
i = 0
lnCount_i = loJarrResp.Size
DO WHILE i < lnCount_i
loJson = loJarrResp.ObjectAt(i)
lnId = loJson.IntOf("id")
lcName = loJson.StringOf("name")
lcSlug = loJson.StringOf("slug")
lcPermalink = loJson.StringOf("permalink")
loJson.DtOf("date_created",0,loDate_created)
loJson.DtOf("date_created_gmt",0,loDate_created_gmt)
loJson.DtOf("date_modified",0,loDate_modified)
loJson.DtOf("date_modified_gmt",0,loDate_modified_gmt)
lcV_type = loJson.StringOf("type")
lcStatus = loJson.StringOf("status")
lnFeatured = loJson.BoolOf("featured")
lcCatalog_visibility = loJson.StringOf("catalog_visibility")
lcDescription = loJson.StringOf("description")
lcShort_description = loJson.StringOf("short_description")
lcSku = loJson.StringOf("sku")
lcPrice = loJson.StringOf("price")
lcRegular_price = loJson.StringOf("regular_price")
lcSale_price = loJson.StringOf("sale_price")
loJson.DtOf("date_on_sale_from",0,loDate_on_sale_from)
loJson.DtOf("date_on_sale_from_gmt",0,loDate_on_sale_from_gmt)
loJson.DtOf("date_on_sale_to",0,loDate_on_sale_to)
loJson.DtOf("date_on_sale_to_gmt",0,loDate_on_sale_to_gmt)
lcPrice_html = loJson.StringOf("price_html")
lnOn_sale = loJson.BoolOf("on_sale")
lnPurchasable = loJson.BoolOf("purchasable")
lnTotal_sales = loJson.IntOf("total_sales")
lnV_virtual = loJson.BoolOf("virtual")
lnDownloadable = loJson.BoolOf("downloadable")
lnDownload_limit = loJson.IntOf("download_limit")
lnDownload_expiry = loJson.IntOf("download_expiry")
lcExternal_url = loJson.StringOf("external_url")
lcButton_text = loJson.StringOf("button_text")
lcTax_status = loJson.StringOf("tax_status")
lcTax_class = loJson.StringOf("tax_class")
lnManage_stock = loJson.BoolOf("manage_stock")
lcStock_quantity = loJson.StringOf("stock_quantity")
lcStock_status = loJson.StringOf("stock_status")
lcBackorders = loJson.StringOf("backorders")
lnBackorders_allowed = loJson.BoolOf("backorders_allowed")
lnBackordered = loJson.BoolOf("backordered")
lnSold_individually = loJson.BoolOf("sold_individually")
lcWeight = loJson.StringOf("weight")
lcDimensionsLength = loJson.StringOf("dimensions.length")
lcDimensionsWidth = loJson.StringOf("dimensions.width")
lcDimensionsHeight = loJson.StringOf("dimensions.height")
lnShipping_required = loJson.BoolOf("shipping_required")
lnShipping_taxable = loJson.BoolOf("shipping_taxable")
lcShipping_class = loJson.StringOf("shipping_class")
lnShipping_class_id = loJson.IntOf("shipping_class_id")
lnReviews_allowed = loJson.BoolOf("reviews_allowed")
lcAverage_rating = loJson.StringOf("average_rating")
lnRating_count = loJson.IntOf("rating_count")
lnParent_id = loJson.IntOf("parent_id")
lcPurchase_note = loJson.StringOf("purchase_note")
lnMenu_order = loJson.IntOf("menu_order")
j = 0
lnCount_j = loJson.SizeOfArray("downloads")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("related_ids")
DO WHILE j < lnCount_j
loJson.J = j
lnIntVal = loJson.IntOf("related_ids[j]")
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("upsell_ids")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("cross_sell_ids")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("categories")
DO WHILE j < lnCount_j
loJson.J = j
lnId = loJson.IntOf("categories[j].id")
lcName = loJson.StringOf("categories[j].name")
lcSlug = loJson.StringOf("categories[j].slug")
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("tags")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("images")
DO WHILE j < lnCount_j
loJson.J = j
lnId = loJson.IntOf("images[j].id")
loJson.DtOf("images[j].date_created",0,loDate_created)
loJson.DtOf("images[j].date_created_gmt",0,loDate_created_gmt)
loJson.DtOf("images[j].date_modified",0,loDate_modified)
loJson.DtOf("images[j].date_modified_gmt",0,loDate_modified_gmt)
lcSrc = loJson.StringOf("images[j].src")
lcName = loJson.StringOf("images[j].name")
lcAlt = loJson.StringOf("images[j].alt")
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("attributes")
DO WHILE j < lnCount_j
loJson.J = j
lnId = loJson.IntOf("attributes[j].id")
lcName = loJson.StringOf("attributes[j].name")
lnPosition = loJson.IntOf("attributes[j].position")
lnVisible = loJson.BoolOf("attributes[j].visible")
lnVariation = loJson.BoolOf("attributes[j].variation")
k = 0
lnCount_k = loJson.SizeOfArray("attributes[j].options")
DO WHILE k < lnCount_k
loJson.K = k
lcStrVal = loJson.StringOf("attributes[j].options[k]")
k = k + 1
ENDDO
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("default_attributes")
DO WHILE j < lnCount_j
loJson.J = j
lnId = loJson.IntOf("default_attributes[j].id")
lcName = loJson.StringOf("default_attributes[j].name")
lcV_option = loJson.StringOf("default_attributes[j].option")
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("variations")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("grouped_products")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("meta_data")
DO WHILE j < lnCount_j
loJson.J = j
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("_links.self")
DO WHILE j < lnCount_j
loJson.J = j
lcHref = loJson.StringOf("_links.self[j].href")
j = j + 1
ENDDO
j = 0
lnCount_j = loJson.SizeOfArray("_links.collection")
DO WHILE j < lnCount_j
loJson.J = j
lcHref = loJson.StringOf("_links.collection[j].href")
j = j + 1
ENDDO
RELEASE loJson
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJarrResp
RELEASE loDate_created
RELEASE loDate_created_gmt
RELEASE loDate_modified
RELEASE loDate_modified_gmt
RELEASE loDate_on_sale_from
RELEASE loDate_on_sale_from_gmt
RELEASE loDate_on_sale_to
RELEASE loDate_on_sale_to_gmt