Lianja
Lianja
WooCommerce List All Products
See more WooCommerce Examples
Gets WooCommerce product information in JSON format.Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("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
loHttp.BasicAuth = .T.
loHttp.Login = "consumer_key"
loHttp.Password = "consumer_secret"
loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://example.com/wp-json/wc/v3/products",loSbResponseBody)
if (llSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loSbResponseBody
return
endif
loJarrResp = createobject("CkJsonArray")
loJarrResp.LoadSb(loSbResponseBody)
loJarrResp.EmitCompact = .F.
? "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
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
loDate_created = createobject("CkDtObj")
loDate_created_gmt = createobject("CkDtObj")
loDate_modified = createobject("CkDtObj")
loDate_modified_gmt = createobject("CkDtObj")
loDate_on_sale_from = createobject("CkDtObj")
loDate_on_sale_from_gmt = createobject("CkDtObj")
loDate_on_sale_to = createobject("CkDtObj")
loDate_on_sale_to_gmt = createobject("CkDtObj")
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",.F.,loDate_created)
loJson.DtOf("date_created_gmt",.F.,loDate_created_gmt)
loJson.DtOf("date_modified",.F.,loDate_modified)
loJson.DtOf("date_modified_gmt",.F.,loDate_modified_gmt)
lcV_type = loJson.StringOf("type")
lcStatus = loJson.StringOf("status")
llFeatured = 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",.F.,loDate_on_sale_from)
loJson.DtOf("date_on_sale_from_gmt",.F.,loDate_on_sale_from_gmt)
loJson.DtOf("date_on_sale_to",.F.,loDate_on_sale_to)
loJson.DtOf("date_on_sale_to_gmt",.F.,loDate_on_sale_to_gmt)
lcPrice_html = loJson.StringOf("price_html")
llOn_sale = loJson.BoolOf("on_sale")
llPurchasable = loJson.BoolOf("purchasable")
lnTotal_sales = loJson.IntOf("total_sales")
llV_virtual = loJson.BoolOf("virtual")
llDownloadable = 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")
llManage_stock = loJson.BoolOf("manage_stock")
lcStock_quantity = loJson.StringOf("stock_quantity")
lcStock_status = loJson.StringOf("stock_status")
lcBackorders = loJson.StringOf("backorders")
llBackorders_allowed = loJson.BoolOf("backorders_allowed")
llBackordered = loJson.BoolOf("backordered")
llSold_individually = loJson.BoolOf("sold_individually")
lcWeight = loJson.StringOf("weight")
lcDimensionsLength = loJson.StringOf("dimensions.length")
lcDimensionsWidth = loJson.StringOf("dimensions.width")
lcDimensionsHeight = loJson.StringOf("dimensions.height")
llShipping_required = loJson.BoolOf("shipping_required")
llShipping_taxable = loJson.BoolOf("shipping_taxable")
lcShipping_class = loJson.StringOf("shipping_class")
lnShipping_class_id = loJson.IntOf("shipping_class_id")
llReviews_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",.F.,loDate_created)
loJson.DtOf("images[j].date_created_gmt",.F.,loDate_created_gmt)
loJson.DtOf("images[j].date_modified",.F.,loDate_modified)
loJson.DtOf("images[j].date_modified_gmt",.F.,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")
llVisible = loJson.BoolOf("attributes[j].visible")
llVariation = 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