Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Tcl Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon MWS
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Jira
MYOB
Magento

MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
Rabobank
SOAP finkok.com
Shippo
Shopify
SimpleTexting
Square
Stripe
SugarCRM
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WooCommerce
Xero
Yousign
_Miscellaneous_
eBay
effectconnect

 

 

 

(Tcl) WooCommerce Delete a Product

Demonstrates how to delete a product from WooCommerce.

For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#delete-a-product

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

set http [new_CkHttp]

# Implements the following CURL command:

# curl -X DELETE https://example.com/wp-json/wc/v3/products/794?force=true \
#     -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

CkHttp_put_Login $http "consumer_key"
CkHttp_put_Password $http "consumer_secret"

# resp is a CkHttpResponse
set resp [CkHttp_QuickRequest $http "DELETE" "https://example.com/wp-json/wc/v3/products/794?force=true"]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttpResponse $resp

    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

delete_CkHttpResponse $resp

# 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": "24.54",
#   "regular_price": "24.54",
#   "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>24.54</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": [
#     479,
#     387,
#     22,
#     463,
#     396
#   ],
#   "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

set date_created [new_CkDtObj]

set date_created_gmt [new_CkDtObj]

set date_modified [new_CkDtObj]

set date_modified_gmt [new_CkDtObj]

set date_on_sale_from [new_CkDtObj]

set date_on_sale_from_gmt [new_CkDtObj]

set date_on_sale_to [new_CkDtObj]

set date_on_sale_to_gmt [new_CkDtObj]

set id [CkJsonObject_IntOf $jResp "id"]
set name [CkJsonObject_stringOf $jResp "name"]
set slug [CkJsonObject_stringOf $jResp "slug"]
set permalink [CkJsonObject_stringOf $jResp "permalink"]
CkJsonObject_DtOf $jResp "date_created" 0 $date_created
CkJsonObject_DtOf $jResp "date_created_gmt" 0 $date_created_gmt
CkJsonObject_DtOf $jResp "date_modified" 0 $date_modified
CkJsonObject_DtOf $jResp "date_modified_gmt" 0 $date_modified_gmt
set v_type [CkJsonObject_stringOf $jResp "type"]
set status [CkJsonObject_stringOf $jResp "status"]
set featured [CkJsonObject_BoolOf $jResp "featured"]
set catalog_visibility [CkJsonObject_stringOf $jResp "catalog_visibility"]
set description [CkJsonObject_stringOf $jResp "description"]
set short_description [CkJsonObject_stringOf $jResp "short_description"]
set sku [CkJsonObject_stringOf $jResp "sku"]
set price [CkJsonObject_stringOf $jResp "price"]
set regular_price [CkJsonObject_stringOf $jResp "regular_price"]
set sale_price [CkJsonObject_stringOf $jResp "sale_price"]
CkJsonObject_DtOf $jResp "date_on_sale_from" 0 $date_on_sale_from
CkJsonObject_DtOf $jResp "date_on_sale_from_gmt" 0 $date_on_sale_from_gmt
CkJsonObject_DtOf $jResp "date_on_sale_to" 0 $date_on_sale_to
CkJsonObject_DtOf $jResp "date_on_sale_to_gmt" 0 $date_on_sale_to_gmt
set price_html [CkJsonObject_stringOf $jResp "price_html"]
set on_sale [CkJsonObject_BoolOf $jResp "on_sale"]
set purchasable [CkJsonObject_BoolOf $jResp "purchasable"]
set total_sales [CkJsonObject_IntOf $jResp "total_sales"]
set virtual [CkJsonObject_BoolOf $jResp "virtual"]
set downloadable [CkJsonObject_BoolOf $jResp "downloadable"]
set download_limit [CkJsonObject_IntOf $jResp "download_limit"]
set download_expiry [CkJsonObject_IntOf $jResp "download_expiry"]
set external_url [CkJsonObject_stringOf $jResp "external_url"]
set button_text [CkJsonObject_stringOf $jResp "button_text"]
set tax_status [CkJsonObject_stringOf $jResp "tax_status"]
set tax_class [CkJsonObject_stringOf $jResp "tax_class"]
set manage_stock [CkJsonObject_BoolOf $jResp "manage_stock"]
set stock_quantity [CkJsonObject_stringOf $jResp "stock_quantity"]
set stock_status [CkJsonObject_stringOf $jResp "stock_status"]
set backorders [CkJsonObject_stringOf $jResp "backorders"]
set backorders_allowed [CkJsonObject_BoolOf $jResp "backorders_allowed"]
set backordered [CkJsonObject_BoolOf $jResp "backordered"]
set sold_individually [CkJsonObject_BoolOf $jResp "sold_individually"]
set weight [CkJsonObject_stringOf $jResp "weight"]
set dimensionsLength [CkJsonObject_stringOf $jResp "dimensions.length"]
set dimensionsWidth [CkJsonObject_stringOf $jResp "dimensions.width"]
set dimensionsHeight [CkJsonObject_stringOf $jResp "dimensions.height"]
set shipping_required [CkJsonObject_BoolOf $jResp "shipping_required"]
set shipping_taxable [CkJsonObject_BoolOf $jResp "shipping_taxable"]
set shipping_class [CkJsonObject_stringOf $jResp "shipping_class"]
set shipping_class_id [CkJsonObject_IntOf $jResp "shipping_class_id"]
set reviews_allowed [CkJsonObject_BoolOf $jResp "reviews_allowed"]
set average_rating [CkJsonObject_stringOf $jResp "average_rating"]
set rating_count [CkJsonObject_IntOf $jResp "rating_count"]
set parent_id [CkJsonObject_IntOf $jResp "parent_id"]
set purchase_note [CkJsonObject_stringOf $jResp "purchase_note"]
set menu_order [CkJsonObject_IntOf $jResp "menu_order"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "downloads"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "related_ids"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set intVal [CkJsonObject_IntOf $jResp "related_ids[i]"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "upsell_ids"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "cross_sell_ids"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "categories"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set id [CkJsonObject_IntOf $jResp "categories[i].id"]
    set name [CkJsonObject_stringOf $jResp "categories[i].name"]
    set slug [CkJsonObject_stringOf $jResp "categories[i].slug"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "tags"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "images"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set id [CkJsonObject_IntOf $jResp "images[i].id"]
    CkJsonObject_DtOf $jResp "images[i].date_created" 0 $date_created
    CkJsonObject_DtOf $jResp "images[i].date_created_gmt" 0 $date_created_gmt
    CkJsonObject_DtOf $jResp "images[i].date_modified" 0 $date_modified
    CkJsonObject_DtOf $jResp "images[i].date_modified_gmt" 0 $date_modified_gmt
    set src [CkJsonObject_stringOf $jResp "images[i].src"]
    set name [CkJsonObject_stringOf $jResp "images[i].name"]
    set alt [CkJsonObject_stringOf $jResp "images[i].alt"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "attributes"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "default_attributes"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "variations"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "grouped_products"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "meta_data"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "_links.self"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set href [CkJsonObject_stringOf $jResp "_links.self[i].href"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "_links.collection"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set href [CkJsonObject_stringOf $jResp "_links.collection[i].href"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
delete_CkDtObj $date_created
delete_CkDtObj $date_created_gmt
delete_CkDtObj $date_modified
delete_CkDtObj $date_modified_gmt
delete_CkDtObj $date_on_sale_from
delete_CkDtObj $date_on_sale_from_gmt
delete_CkDtObj $date_on_sale_to
delete_CkDtObj $date_on_sale_to_gmt

 

© 2000-2020 Chilkat Software, Inc. All Rights Reserved.