Sample code for 30+ languages & platforms
PowerBuilder

WooCommerce List All Products

See more WooCommerce Examples

Gets WooCommerce product information in JSON format.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JarrResp
long li_RespStatusCode
oleobject loo_Date_created
oleobject loo_Date_created_gmt
oleobject loo_Date_modified
oleobject loo_Date_modified_gmt
oleobject loo_Date_on_sale_from
oleobject loo_Date_on_sale_from_gmt
oleobject loo_Date_on_sale_to
oleobject loo_Date_on_sale_to_gmt
oleobject loo_Json
long li_Id
string ls_Name
string ls_Slug
string ls_Permalink
string ls_V_type
string ls_Status
long li_Featured
string ls_Catalog_visibility
string ls_Description
string ls_Short_description
string ls_Sku
string ls_Price
string ls_Regular_price
string ls_Sale_price
string ls_Price_html
long li_On_sale
long li_Purchasable
long li_Total_sales
long li_V_virtual
long li_Downloadable
long li_Download_limit
long li_Download_expiry
string ls_External_url
string ls_Button_text
string ls_Tax_status
string ls_Tax_class
long li_Manage_stock
string ls_Stock_quantity
string ls_Stock_status
string ls_Backorders
long li_Backorders_allowed
long li_Backordered
long li_Sold_individually
string ls_Weight
string ls_DimensionsLength
string ls_DimensionsWidth
string ls_DimensionsHeight
long li_Shipping_required
long li_Shipping_taxable
string ls_Shipping_class
long li_Shipping_class_id
long li_Reviews_allowed
string ls_Average_rating
long li_Rating_count
long li_Parent_id
string ls_Purchase_note
long li_Menu_order
long j
long li_Count_j
long li_IntVal
string ls_Src
string ls_Alt
long li_Position
long li_Visible
long li_Variation
long k
long li_Count_k
string ls_StrVal
string ls_V_option
string ls_Href
long i
long li_Count_i

li_Success = 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  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

loo_Http.BasicAuth = 1
loo_Http.Login = "consumer_key"
loo_Http.Password = "consumer_secret"

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://example.com/wp-json/wc/v3/products",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JarrResp = create oleobject
li_rc = loo_JarrResp.ConnectToNewObject("Chilkat.JsonArray")

loo_JarrResp.LoadSb(loo_SbResponseBody)
loo_JarrResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JarrResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JarrResp
    return
end if

//  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\">&#36;</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

loo_Date_created = create oleobject
li_rc = loo_Date_created.ConnectToNewObject("Chilkat.DtObj")

loo_Date_created_gmt = create oleobject
li_rc = loo_Date_created_gmt.ConnectToNewObject("Chilkat.DtObj")

loo_Date_modified = create oleobject
li_rc = loo_Date_modified.ConnectToNewObject("Chilkat.DtObj")

loo_Date_modified_gmt = create oleobject
li_rc = loo_Date_modified_gmt.ConnectToNewObject("Chilkat.DtObj")

loo_Date_on_sale_from = create oleobject
li_rc = loo_Date_on_sale_from.ConnectToNewObject("Chilkat.DtObj")

loo_Date_on_sale_from_gmt = create oleobject
li_rc = loo_Date_on_sale_from_gmt.ConnectToNewObject("Chilkat.DtObj")

loo_Date_on_sale_to = create oleobject
li_rc = loo_Date_on_sale_to.ConnectToNewObject("Chilkat.DtObj")

loo_Date_on_sale_to_gmt = create oleobject
li_rc = loo_Date_on_sale_to_gmt.ConnectToNewObject("Chilkat.DtObj")

i = 0
li_Count_i = loo_JarrResp.Size
do while i < li_Count_i
    loo_Json = loo_JarrResp.ObjectAt(i)
    li_Id = loo_Json.IntOf("id")
    ls_Name = loo_Json.StringOf("name")
    ls_Slug = loo_Json.StringOf("slug")
    ls_Permalink = loo_Json.StringOf("permalink")
    loo_Json.DtOf("date_created",0,loo_Date_created)
    loo_Json.DtOf("date_created_gmt",0,loo_Date_created_gmt)
    loo_Json.DtOf("date_modified",0,loo_Date_modified)
    loo_Json.DtOf("date_modified_gmt",0,loo_Date_modified_gmt)
    ls_V_type = loo_Json.StringOf("type")
    ls_Status = loo_Json.StringOf("status")
    li_Featured = loo_Json.BoolOf("featured")
    ls_Catalog_visibility = loo_Json.StringOf("catalog_visibility")
    ls_Description = loo_Json.StringOf("description")
    ls_Short_description = loo_Json.StringOf("short_description")
    ls_Sku = loo_Json.StringOf("sku")
    ls_Price = loo_Json.StringOf("price")
    ls_Regular_price = loo_Json.StringOf("regular_price")
    ls_Sale_price = loo_Json.StringOf("sale_price")
    loo_Json.DtOf("date_on_sale_from",0,loo_Date_on_sale_from)
    loo_Json.DtOf("date_on_sale_from_gmt",0,loo_Date_on_sale_from_gmt)
    loo_Json.DtOf("date_on_sale_to",0,loo_Date_on_sale_to)
    loo_Json.DtOf("date_on_sale_to_gmt",0,loo_Date_on_sale_to_gmt)
    ls_Price_html = loo_Json.StringOf("price_html")
    li_On_sale = loo_Json.BoolOf("on_sale")
    li_Purchasable = loo_Json.BoolOf("purchasable")
    li_Total_sales = loo_Json.IntOf("total_sales")
    li_V_virtual = loo_Json.BoolOf("virtual")
    li_Downloadable = loo_Json.BoolOf("downloadable")
    li_Download_limit = loo_Json.IntOf("download_limit")
    li_Download_expiry = loo_Json.IntOf("download_expiry")
    ls_External_url = loo_Json.StringOf("external_url")
    ls_Button_text = loo_Json.StringOf("button_text")
    ls_Tax_status = loo_Json.StringOf("tax_status")
    ls_Tax_class = loo_Json.StringOf("tax_class")
    li_Manage_stock = loo_Json.BoolOf("manage_stock")
    ls_Stock_quantity = loo_Json.StringOf("stock_quantity")
    ls_Stock_status = loo_Json.StringOf("stock_status")
    ls_Backorders = loo_Json.StringOf("backorders")
    li_Backorders_allowed = loo_Json.BoolOf("backorders_allowed")
    li_Backordered = loo_Json.BoolOf("backordered")
    li_Sold_individually = loo_Json.BoolOf("sold_individually")
    ls_Weight = loo_Json.StringOf("weight")
    ls_DimensionsLength = loo_Json.StringOf("dimensions.length")
    ls_DimensionsWidth = loo_Json.StringOf("dimensions.width")
    ls_DimensionsHeight = loo_Json.StringOf("dimensions.height")
    li_Shipping_required = loo_Json.BoolOf("shipping_required")
    li_Shipping_taxable = loo_Json.BoolOf("shipping_taxable")
    ls_Shipping_class = loo_Json.StringOf("shipping_class")
    li_Shipping_class_id = loo_Json.IntOf("shipping_class_id")
    li_Reviews_allowed = loo_Json.BoolOf("reviews_allowed")
    ls_Average_rating = loo_Json.StringOf("average_rating")
    li_Rating_count = loo_Json.IntOf("rating_count")
    li_Parent_id = loo_Json.IntOf("parent_id")
    ls_Purchase_note = loo_Json.StringOf("purchase_note")
    li_Menu_order = loo_Json.IntOf("menu_order")
    j = 0
    li_Count_j = loo_Json.SizeOfArray("downloads")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("related_ids")
    do while j < li_Count_j
        loo_Json.J = j
        li_IntVal = loo_Json.IntOf("related_ids[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("upsell_ids")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("cross_sell_ids")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("categories")
    do while j < li_Count_j
        loo_Json.J = j
        li_Id = loo_Json.IntOf("categories[j].id")
        ls_Name = loo_Json.StringOf("categories[j].name")
        ls_Slug = loo_Json.StringOf("categories[j].slug")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("tags")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("images")
    do while j < li_Count_j
        loo_Json.J = j
        li_Id = loo_Json.IntOf("images[j].id")
        loo_Json.DtOf("images[j].date_created",0,loo_Date_created)
        loo_Json.DtOf("images[j].date_created_gmt",0,loo_Date_created_gmt)
        loo_Json.DtOf("images[j].date_modified",0,loo_Date_modified)
        loo_Json.DtOf("images[j].date_modified_gmt",0,loo_Date_modified_gmt)
        ls_Src = loo_Json.StringOf("images[j].src")
        ls_Name = loo_Json.StringOf("images[j].name")
        ls_Alt = loo_Json.StringOf("images[j].alt")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("attributes")
    do while j < li_Count_j
        loo_Json.J = j
        li_Id = loo_Json.IntOf("attributes[j].id")
        ls_Name = loo_Json.StringOf("attributes[j].name")
        li_Position = loo_Json.IntOf("attributes[j].position")
        li_Visible = loo_Json.BoolOf("attributes[j].visible")
        li_Variation = loo_Json.BoolOf("attributes[j].variation")
        k = 0
        li_Count_k = loo_Json.SizeOfArray("attributes[j].options")
        do while k < li_Count_k
            loo_Json.K = k
            ls_StrVal = loo_Json.StringOf("attributes[j].options[k]")
            k = k + 1
        loop
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("default_attributes")
    do while j < li_Count_j
        loo_Json.J = j
        li_Id = loo_Json.IntOf("default_attributes[j].id")
        ls_Name = loo_Json.StringOf("default_attributes[j].name")
        ls_V_option = loo_Json.StringOf("default_attributes[j].option")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("variations")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("grouped_products")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("meta_data")
    do while j < li_Count_j
        loo_Json.J = j
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("_links.self")
    do while j < li_Count_j
        loo_Json.J = j
        ls_Href = loo_Json.StringOf("_links.self[j].href")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("_links.collection")
    do while j < li_Count_j
        loo_Json.J = j
        ls_Href = loo_Json.StringOf("_links.collection[j].href")
        j = j + 1
    loop
    destroy loo_Json
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JarrResp
destroy loo_Date_created
destroy loo_Date_created_gmt
destroy loo_Date_modified
destroy loo_Date_modified_gmt
destroy loo_Date_on_sale_from
destroy loo_Date_on_sale_from_gmt
destroy loo_Date_on_sale_to
destroy loo_Date_on_sale_to_gmt