Sample code for 30+ languages & platforms
Go

WooCommerce List All Products

See more WooCommerce Examples

Gets WooCommerce product information in JSON format.

Chilkat Go Downloads

Go
    success := false

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

    http := chilkat.NewHttp()

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

    http.SetBasicAuth(true)
    http.SetLogin("consumer_key")
    http.SetPassword("consumer_secret")

    sbResponseBody := chilkat.NewStringBuilder()
    success = http.QuickGetSb("https://example.com/wp-json/wc/v3/products",sbResponseBody)
    if success == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        sbResponseBody.DisposeStringBuilder()
        return
    }

    jarrResp := chilkat.NewJsonArray()
    jarrResp.LoadSb(sbResponseBody)
    jarrResp.SetEmitCompact(false)

    fmt.Println("Response Body:")
    fmt.Println(*jarrResp.Emit())

    respStatusCode := http.LastStatus()
    fmt.Println("Response Status Code = ", respStatusCode)
    if respStatusCode >= 400 {
        fmt.Println("Response Header:")
        fmt.Println(http.LastHeader())
        fmt.Println("Failed.")
        http.DisposeHttp()
        sbResponseBody.DisposeStringBuilder()
        jarrResp.DisposeJsonArray()
        return
    }

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

    date_created := chilkat.NewDtObj()
    date_created_gmt := chilkat.NewDtObj()
    date_modified := chilkat.NewDtObj()
    date_modified_gmt := chilkat.NewDtObj()
    date_on_sale_from := chilkat.NewDtObj()
    date_on_sale_from_gmt := chilkat.NewDtObj()
    date_on_sale_to := chilkat.NewDtObj()
    date_on_sale_to_gmt := chilkat.NewDtObj()
    // json is a JsonObject
    var id int
    var name *string = new(string)
    var slug *string = new(string)
    var permalink *string = new(string)
    var v_type *string = new(string)
    var status *string = new(string)
    var featured bool
    var catalog_visibility *string = new(string)
    var description *string = new(string)
short_    var description *string = new(string)
    var sku *string = new(string)
    var price *string = new(string)
regular_    var price *string = new(string)
sale_    var price *string = new(string)
    var price_html *string = new(string)
    var on_sale bool
    var purchasable bool
    var total_sales int
    var v_virtual bool
    var downloadable bool
    var download_limit int
    var download_expiry int
    var external_url *string = new(string)
    var button_text *string = new(string)
    var tax_status *string = new(string)
    var tax_class *string = new(string)
    var manage_stock bool
    var stock_quantity *string = new(string)
    var stock_status *string = new(string)
    var backorders *string = new(string)
    var backorders_allowed bool
    var backordered bool
    var sold_individually bool
    var weight *string = new(string)
    var dimensionsLength *string = new(string)
    var dimensionsWidth *string = new(string)
    var dimensionsHeight *string = new(string)
    var shipping_required bool
    var shipping_taxable bool
    var shipping_class *string = new(string)
    var shipping_class_id int
    var reviews_allowed bool
    var average_rating *string = new(string)
    var rating_count int
    var parent_id int
    var purchase_note *string = new(string)
    var menu_order int
    var j int
    var count_j int
    var intVal int
    var src *string = new(string)
    var alt *string = new(string)
    var position int
    var visible bool
    var variation bool
    var k int
    var count_k int
    var strVal *string = new(string)
    var v_option *string = new(string)
    var href *string = new(string)

    i := 0
    count_i := jarrResp.Size()
    for i < count_i {
        json := jarrResp.ObjectAt(i)
        id = json.IntOf("id")
        name = json.StringOf("name")
        slug = json.StringOf("slug")
        permalink = json.StringOf("permalink")
        json.DtOf("date_created",false,date_created)
        json.DtOf("date_created_gmt",false,date_created_gmt)
        json.DtOf("date_modified",false,date_modified)
        json.DtOf("date_modified_gmt",false,date_modified_gmt)
        v_type = json.StringOf("type")
        status = json.StringOf("status")
        featured = json.BoolOf("featured")
        catalog_visibility = json.StringOf("catalog_visibility")
        description = json.StringOf("description")
        short_description = json.StringOf("short_description")
        sku = json.StringOf("sku")
        price = json.StringOf("price")
        regular_price = json.StringOf("regular_price")
        sale_price = json.StringOf("sale_price")
        json.DtOf("date_on_sale_from",false,date_on_sale_from)
        json.DtOf("date_on_sale_from_gmt",false,date_on_sale_from_gmt)
        json.DtOf("date_on_sale_to",false,date_on_sale_to)
        json.DtOf("date_on_sale_to_gmt",false,date_on_sale_to_gmt)
        price_html = json.StringOf("price_html")
        on_sale = json.BoolOf("on_sale")
        purchasable = json.BoolOf("purchasable")
        total_sales = json.IntOf("total_sales")
        v_virtual = json.BoolOf("virtual")
        downloadable = json.BoolOf("downloadable")
        download_limit = json.IntOf("download_limit")
        download_expiry = json.IntOf("download_expiry")
        external_url = json.StringOf("external_url")
        button_text = json.StringOf("button_text")
        tax_status = json.StringOf("tax_status")
        tax_class = json.StringOf("tax_class")
        manage_stock = json.BoolOf("manage_stock")
        stock_quantity = json.StringOf("stock_quantity")
        stock_status = json.StringOf("stock_status")
        backorders = json.StringOf("backorders")
        backorders_allowed = json.BoolOf("backorders_allowed")
        backordered = json.BoolOf("backordered")
        sold_individually = json.BoolOf("sold_individually")
        weight = json.StringOf("weight")
        dimensionsLength = json.StringOf("dimensions.length")
        dimensionsWidth = json.StringOf("dimensions.width")
        dimensionsHeight = json.StringOf("dimensions.height")
        shipping_required = json.BoolOf("shipping_required")
        shipping_taxable = json.BoolOf("shipping_taxable")
        shipping_class = json.StringOf("shipping_class")
        shipping_class_id = json.IntOf("shipping_class_id")
        reviews_allowed = json.BoolOf("reviews_allowed")
        average_rating = json.StringOf("average_rating")
        rating_count = json.IntOf("rating_count")
        parent_id = json.IntOf("parent_id")
        purchase_note = json.StringOf("purchase_note")
        menu_order = json.IntOf("menu_order")
        j = 0
        count_j = json.SizeOfArray("downloads")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("related_ids")
        for j < count_j {
            json.SetJ(j)
            intVal = json.IntOf("related_ids[j]")
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("upsell_ids")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("cross_sell_ids")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("categories")
        for j < count_j {
            json.SetJ(j)
            id = json.IntOf("categories[j].id")
            name = json.StringOf("categories[j].name")
            slug = json.StringOf("categories[j].slug")
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("tags")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("images")
        for j < count_j {
            json.SetJ(j)
            id = json.IntOf("images[j].id")
            json.DtOf("images[j].date_created",false,date_created)
            json.DtOf("images[j].date_created_gmt",false,date_created_gmt)
            json.DtOf("images[j].date_modified",false,date_modified)
            json.DtOf("images[j].date_modified_gmt",false,date_modified_gmt)
            src = json.StringOf("images[j].src")
            name = json.StringOf("images[j].name")
            alt = json.StringOf("images[j].alt")
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("attributes")
        for j < count_j {
            json.SetJ(j)
            id = json.IntOf("attributes[j].id")
            name = json.StringOf("attributes[j].name")
            position = json.IntOf("attributes[j].position")
            visible = json.BoolOf("attributes[j].visible")
            variation = json.BoolOf("attributes[j].variation")
            k = 0
            count_k = json.SizeOfArray("attributes[j].options")
            for k < count_k {
                json.SetK(k)
                strVal = json.StringOf("attributes[j].options[k]")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("default_attributes")
        for j < count_j {
            json.SetJ(j)
            id = json.IntOf("default_attributes[j].id")
            name = json.StringOf("default_attributes[j].name")
            v_option = json.StringOf("default_attributes[j].option")
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("variations")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("grouped_products")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("meta_data")
        for j < count_j {
            json.SetJ(j)
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("_links.self")
        for j < count_j {
            json.SetJ(j)
            href = json.StringOf("_links.self[j].href")
            j = j + 1
        }

        j = 0
        count_j = json.SizeOfArray("_links.collection")
        for j < count_j {
            json.SetJ(j)
            href = json.StringOf("_links.collection[j].href")
            j = j + 1
        }

        json.DisposeJsonObject()
        i = i + 1
    }


    http.DisposeHttp()
    sbResponseBody.DisposeStringBuilder()
    jarrResp.DisposeJsonArray()
    date_created.DisposeDtObj()
    date_created_gmt.DisposeDtObj()
    date_modified.DisposeDtObj()
    date_modified_gmt.DisposeDtObj()
    date_on_sale_from.DisposeDtObj()
    date_on_sale_from_gmt.DisposeDtObj()
    date_on_sale_to.DisposeDtObj()
    date_on_sale_to_gmt.DisposeDtObj()