Xbase++
Xbase++
WooCommerce List All Products
See more WooCommerce Examples
Gets WooCommerce product information in JSON format.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJarrResp
LOCAL nRespStatusCode
LOCAL oDate_created
LOCAL oDate_created_gmt
LOCAL oDate_modified
LOCAL oDate_modified_gmt
LOCAL oDate_on_sale_from
LOCAL oDate_on_sale_from_gmt
LOCAL oDate_on_sale_to
LOCAL oDate_on_sale_to_gmt
LOCAL oJson
LOCAL nId
LOCAL cName
LOCAL cSlug
LOCAL cPermalink
LOCAL cV_type
LOCAL cStatus
LOCAL nFeatured
LOCAL cCatalog_visibility
LOCAL cDescription
LOCAL cShort_description
LOCAL cSku
LOCAL cPrice
LOCAL cRegular_price
LOCAL cSale_price
LOCAL cPrice_html
LOCAL nOn_sale
LOCAL nPurchasable
LOCAL nTotal_sales
LOCAL nV_virtual
LOCAL nDownloadable
LOCAL nDownload_limit
LOCAL nDownload_expiry
LOCAL cExternal_url
LOCAL cButton_text
LOCAL cTax_status
LOCAL cTax_class
LOCAL nManage_stock
LOCAL cStock_quantity
LOCAL cStock_status
LOCAL cBackorders
LOCAL nBackorders_allowed
LOCAL nBackordered
LOCAL nSold_individually
LOCAL cWeight
LOCAL cDimensionsLength
LOCAL cDimensionsWidth
LOCAL cDimensionsHeight
LOCAL nShipping_required
LOCAL nShipping_taxable
LOCAL cShipping_class
LOCAL nShipping_class_id
LOCAL nReviews_allowed
LOCAL cAverage_rating
LOCAL nRating_count
LOCAL nParent_id
LOCAL cPurchase_note
LOCAL nMenu_order
LOCAL j
LOCAL nCount_j
LOCAL nIntVal
LOCAL cSrc
LOCAL cAlt
LOCAL nPosition
LOCAL nVisible
LOCAL nVariation
LOCAL k
LOCAL nCount_k
LOCAL cStrVal
LOCAL cV_option
LOCAL cHref
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := 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
oHttp:BasicAuth := 1
oHttp:Login := "consumer_key"
oHttp:Password := "consumer_secret"
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://example.com/wp-json/wc/v3/products", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJarrResp := CreateObject("Chilkat.JsonArray")
oJarrResp:LoadSb(oSbResponseBody)
oJarrResp:EmitCompact := 0
? "Response Body:"
? oJarrResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()
RETURN
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
oDate_created := CreateObject("Chilkat.DtObj")
oDate_created_gmt := CreateObject("Chilkat.DtObj")
oDate_modified := CreateObject("Chilkat.DtObj")
oDate_modified_gmt := CreateObject("Chilkat.DtObj")
oDate_on_sale_from := CreateObject("Chilkat.DtObj")
oDate_on_sale_from_gmt := CreateObject("Chilkat.DtObj")
oDate_on_sale_to := CreateObject("Chilkat.DtObj")
oDate_on_sale_to_gmt := CreateObject("Chilkat.DtObj")
i := 0
nCount_i := oJarrResp:Size
DO WHILE i < nCount_i
oJson := oJarrResp:ObjectAt(i)
nId := oJson:IntOf("id")
cName := oJson:StringOf("name")
cSlug := oJson:StringOf("slug")
cPermalink := oJson:StringOf("permalink")
oJson:DtOf("date_created", 0, oDate_created)
oJson:DtOf("date_created_gmt", 0, oDate_created_gmt)
oJson:DtOf("date_modified", 0, oDate_modified)
oJson:DtOf("date_modified_gmt", 0, oDate_modified_gmt)
cV_type := oJson:StringOf("type")
cStatus := oJson:StringOf("status")
nFeatured := oJson:BoolOf("featured")
cCatalog_visibility := oJson:StringOf("catalog_visibility")
cDescription := oJson:StringOf("description")
cShort_description := oJson:StringOf("short_description")
cSku := oJson:StringOf("sku")
cPrice := oJson:StringOf("price")
cRegular_price := oJson:StringOf("regular_price")
cSale_price := oJson:StringOf("sale_price")
oJson:DtOf("date_on_sale_from", 0, oDate_on_sale_from)
oJson:DtOf("date_on_sale_from_gmt", 0, oDate_on_sale_from_gmt)
oJson:DtOf("date_on_sale_to", 0, oDate_on_sale_to)
oJson:DtOf("date_on_sale_to_gmt", 0, oDate_on_sale_to_gmt)
cPrice_html := oJson:StringOf("price_html")
nOn_sale := oJson:BoolOf("on_sale")
nPurchasable := oJson:BoolOf("purchasable")
nTotal_sales := oJson:IntOf("total_sales")
nV_virtual := oJson:BoolOf("virtual")
nDownloadable := oJson:BoolOf("downloadable")
nDownload_limit := oJson:IntOf("download_limit")
nDownload_expiry := oJson:IntOf("download_expiry")
cExternal_url := oJson:StringOf("external_url")
cButton_text := oJson:StringOf("button_text")
cTax_status := oJson:StringOf("tax_status")
cTax_class := oJson:StringOf("tax_class")
nManage_stock := oJson:BoolOf("manage_stock")
cStock_quantity := oJson:StringOf("stock_quantity")
cStock_status := oJson:StringOf("stock_status")
cBackorders := oJson:StringOf("backorders")
nBackorders_allowed := oJson:BoolOf("backorders_allowed")
nBackordered := oJson:BoolOf("backordered")
nSold_individually := oJson:BoolOf("sold_individually")
cWeight := oJson:StringOf("weight")
cDimensionsLength := oJson:StringOf("dimensions.length")
cDimensionsWidth := oJson:StringOf("dimensions.width")
cDimensionsHeight := oJson:StringOf("dimensions.height")
nShipping_required := oJson:BoolOf("shipping_required")
nShipping_taxable := oJson:BoolOf("shipping_taxable")
cShipping_class := oJson:StringOf("shipping_class")
nShipping_class_id := oJson:IntOf("shipping_class_id")
nReviews_allowed := oJson:BoolOf("reviews_allowed")
cAverage_rating := oJson:StringOf("average_rating")
nRating_count := oJson:IntOf("rating_count")
nParent_id := oJson:IntOf("parent_id")
cPurchase_note := oJson:StringOf("purchase_note")
nMenu_order := oJson:IntOf("menu_order")
j := 0
nCount_j := oJson:SizeOfArray("downloads")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("related_ids")
DO WHILE j < nCount_j
oJson:J := j
nIntVal := oJson:IntOf("related_ids[j]")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("upsell_ids")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("cross_sell_ids")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("categories")
DO WHILE j < nCount_j
oJson:J := j
nId := oJson:IntOf("categories[j].id")
cName := oJson:StringOf("categories[j].name")
cSlug := oJson:StringOf("categories[j].slug")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("tags")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("images")
DO WHILE j < nCount_j
oJson:J := j
nId := oJson:IntOf("images[j].id")
oJson:DtOf("images[j].date_created", 0, oDate_created)
oJson:DtOf("images[j].date_created_gmt", 0, oDate_created_gmt)
oJson:DtOf("images[j].date_modified", 0, oDate_modified)
oJson:DtOf("images[j].date_modified_gmt", 0, oDate_modified_gmt)
cSrc := oJson:StringOf("images[j].src")
cName := oJson:StringOf("images[j].name")
cAlt := oJson:StringOf("images[j].alt")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("attributes")
DO WHILE j < nCount_j
oJson:J := j
nId := oJson:IntOf("attributes[j].id")
cName := oJson:StringOf("attributes[j].name")
nPosition := oJson:IntOf("attributes[j].position")
nVisible := oJson:BoolOf("attributes[j].visible")
nVariation := oJson:BoolOf("attributes[j].variation")
k := 0
nCount_k := oJson:SizeOfArray("attributes[j].options")
DO WHILE k < nCount_k
oJson:K := k
cStrVal := oJson:StringOf("attributes[j].options[k]")
k := k + 1
ENDDO
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("default_attributes")
DO WHILE j < nCount_j
oJson:J := j
nId := oJson:IntOf("default_attributes[j].id")
cName := oJson:StringOf("default_attributes[j].name")
cV_option := oJson:StringOf("default_attributes[j].option")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("variations")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("grouped_products")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("meta_data")
DO WHILE j < nCount_j
oJson:J := j
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.self")
DO WHILE j < nCount_j
oJson:J := j
cHref := oJson:StringOf("_links.self[j].href")
j := j + 1
ENDDO
j := 0
nCount_j := oJson:SizeOfArray("_links.collection")
DO WHILE j < nCount_j
oJson:J := j
cHref := oJson:StringOf("_links.collection[j].href")
j := j + 1
ENDDO
oJson:destroy()
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJarrResp:destroy()
oDate_created:destroy()
oDate_created_gmt:destroy()
oDate_modified:destroy()
oDate_modified_gmt:destroy()
oDate_on_sale_from:destroy()
oDate_on_sale_from_gmt:destroy()
oDate_on_sale_to:destroy()
oDate_on_sale_to_gmt:destroy()