PowerBuilder
PowerBuilder
WooCommerce Create a Product
See more WooCommerce Examples
Demonstrates how to create a new product in WooCommerce.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
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
long li_IntVal
string ls_Src
string ls_Alt
string ls_Href
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_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 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 -X POST https://example.com/wp-json/wc/v3/products \
// -u consumer_key:consumer_secret \
// -H "Content-Type: application/json" \
// -d '{
// "name": "Premium Quality",
// "type": "simple",
// "regular_price": "21.99",
// "description": "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.",
// "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
// "categories": [
// {
// "id": 9
// },
// {
// "id": 14
// }
// ],
// "images": [
// {
// "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
// },
// {
// "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
// }
// ]
// }'
// 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"
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "name": "Premium Quality",
// "type": "simple",
// "regular_price": "21.99",
// "description": "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.",
// "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
// "categories": [
// {
// "id": 9
// },
// {
// "id": 14
// }
// ],
// "images": [
// {
// "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
// },
// {
// "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
// }
// ]
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("name","Premium Quality")
loo_Json.UpdateString("type","simple")
loo_Json.UpdateString("regular_price","21.99")
loo_Json.UpdateString("description","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.")
loo_Json.UpdateString("short_description","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.")
loo_Json.UpdateInt("categories[0].id",9)
loo_Json.UpdateInt("categories[1].id",14)
loo_Json.UpdateString("images[0].src","http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg")
loo_Json.UpdateString("images[1].src","http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpJson("POST","https://example.com/wp-json/wc/v3/products",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_Resp
return
end if
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "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": [
// 53,
// 40,
// 56,
// 479,
// 99
// ],
// "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": [
// ],
// "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")
li_Id = loo_JResp.IntOf("id")
ls_Name = loo_JResp.StringOf("name")
ls_Slug = loo_JResp.StringOf("slug")
ls_Permalink = loo_JResp.StringOf("permalink")
loo_JResp.DtOf("date_created",0,loo_Date_created)
loo_JResp.DtOf("date_created_gmt",0,loo_Date_created_gmt)
loo_JResp.DtOf("date_modified",0,loo_Date_modified)
loo_JResp.DtOf("date_modified_gmt",0,loo_Date_modified_gmt)
ls_V_type = loo_JResp.StringOf("type")
ls_Status = loo_JResp.StringOf("status")
li_Featured = loo_JResp.BoolOf("featured")
ls_Catalog_visibility = loo_JResp.StringOf("catalog_visibility")
ls_Description = loo_JResp.StringOf("description")
ls_Short_description = loo_JResp.StringOf("short_description")
ls_Sku = loo_JResp.StringOf("sku")
ls_Price = loo_JResp.StringOf("price")
ls_Regular_price = loo_JResp.StringOf("regular_price")
ls_Sale_price = loo_JResp.StringOf("sale_price")
loo_JResp.DtOf("date_on_sale_from",0,loo_Date_on_sale_from)
loo_JResp.DtOf("date_on_sale_from_gmt",0,loo_Date_on_sale_from_gmt)
loo_JResp.DtOf("date_on_sale_to",0,loo_Date_on_sale_to)
loo_JResp.DtOf("date_on_sale_to_gmt",0,loo_Date_on_sale_to_gmt)
ls_Price_html = loo_JResp.StringOf("price_html")
li_On_sale = loo_JResp.BoolOf("on_sale")
li_Purchasable = loo_JResp.BoolOf("purchasable")
li_Total_sales = loo_JResp.IntOf("total_sales")
li_Virtual = loo_JResp.BoolOf("virtual")
li_Downloadable = loo_JResp.BoolOf("downloadable")
li_Download_limit = loo_JResp.IntOf("download_limit")
li_Download_expiry = loo_JResp.IntOf("download_expiry")
ls_External_url = loo_JResp.StringOf("external_url")
ls_Button_text = loo_JResp.StringOf("button_text")
ls_Tax_status = loo_JResp.StringOf("tax_status")
ls_Tax_class = loo_JResp.StringOf("tax_class")
li_Manage_stock = loo_JResp.BoolOf("manage_stock")
ls_Stock_quantity = loo_JResp.StringOf("stock_quantity")
ls_Stock_status = loo_JResp.StringOf("stock_status")
ls_Backorders = loo_JResp.StringOf("backorders")
li_Backorders_allowed = loo_JResp.BoolOf("backorders_allowed")
li_Backordered = loo_JResp.BoolOf("backordered")
li_Sold_individually = loo_JResp.BoolOf("sold_individually")
ls_Weight = loo_JResp.StringOf("weight")
ls_DimensionsLength = loo_JResp.StringOf("dimensions.length")
ls_DimensionsWidth = loo_JResp.StringOf("dimensions.width")
ls_DimensionsHeight = loo_JResp.StringOf("dimensions.height")
li_Shipping_required = loo_JResp.BoolOf("shipping_required")
li_Shipping_taxable = loo_JResp.BoolOf("shipping_taxable")
ls_Shipping_class = loo_JResp.StringOf("shipping_class")
li_Shipping_class_id = loo_JResp.IntOf("shipping_class_id")
li_Reviews_allowed = loo_JResp.BoolOf("reviews_allowed")
ls_Average_rating = loo_JResp.StringOf("average_rating")
li_Rating_count = loo_JResp.IntOf("rating_count")
li_Parent_id = loo_JResp.IntOf("parent_id")
ls_Purchase_note = loo_JResp.StringOf("purchase_note")
li_Menu_order = loo_JResp.IntOf("menu_order")
i = 0
li_Count_i = loo_JResp.SizeOfArray("downloads")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("related_ids")
do while i < li_Count_i
loo_JResp.I = i
li_IntVal = loo_JResp.IntOf("related_ids[i]")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("upsell_ids")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("cross_sell_ids")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("categories")
do while i < li_Count_i
loo_JResp.I = i
li_Id = loo_JResp.IntOf("categories[i].id")
ls_Name = loo_JResp.StringOf("categories[i].name")
ls_Slug = loo_JResp.StringOf("categories[i].slug")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("tags")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("images")
do while i < li_Count_i
loo_JResp.I = i
li_Id = loo_JResp.IntOf("images[i].id")
loo_JResp.DtOf("images[i].date_created",0,loo_Date_created)
loo_JResp.DtOf("images[i].date_created_gmt",0,loo_Date_created_gmt)
loo_JResp.DtOf("images[i].date_modified",0,loo_Date_modified)
loo_JResp.DtOf("images[i].date_modified_gmt",0,loo_Date_modified_gmt)
ls_Src = loo_JResp.StringOf("images[i].src")
ls_Name = loo_JResp.StringOf("images[i].name")
ls_Alt = loo_JResp.StringOf("images[i].alt")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("attributes")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("default_attributes")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("variations")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("grouped_products")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("meta_data")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("_links.self")
do while i < li_Count_i
loo_JResp.I = i
ls_Href = loo_JResp.StringOf("_links.self[i].href")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("_links.collection")
do while i < li_Count_i
loo_JResp.I = i
ls_Href = loo_JResp.StringOf("_links.collection[i].href")
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp
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