Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) WooCommerce Create a ProductSee more WooCommerce ExamplesDemonstrates how to create a new product in WooCommerce. For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-product
// 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 -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 loHttp.BasicAuth = .T. loHttp.Login = "consumer_key" loHttp.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" // } // ] // } loJson = createobject("CkJsonObject") loJson.UpdateString("name","Premium Quality") loJson.UpdateString("type","simple") loJson.UpdateString("regular_price","21.99") loJson.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.") loJson.UpdateString("short_description","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.") loJson.UpdateInt("categories[0].id",9) loJson.UpdateInt("categories[1].id",14) loJson.UpdateString("images[0].src","http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg") loJson.UpdateString("images[1].src","http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg") loHttp.SetRequestHeader("Content-Type","application/json") loResp = loHttp.PostJson3("https://example.com/wp-json/wc/v3/products","application/json",loJson) if (loHttp.LastMethodSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loJson return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + str(lnRespStatusCode) if (lnRespStatusCode >= 400) then ? "Response Header:" ? loResp.Header ? "Failed." release loResp release loHttp release loJson release loSbResponseBody release loJResp return endif release loResp // 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 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") lnId = loJResp.IntOf("id") lcName = loJResp.StringOf("name") lcSlug = loJResp.StringOf("slug") lcPermalink = loJResp.StringOf("permalink") loJResp.DtOf("date_created",.F.,loDate_created) loJResp.DtOf("date_created_gmt",.F.,loDate_created_gmt) loJResp.DtOf("date_modified",.F.,loDate_modified) loJResp.DtOf("date_modified_gmt",.F.,loDate_modified_gmt) lcV_type = loJResp.StringOf("type") lcStatus = loJResp.StringOf("status") llFeatured = loJResp.BoolOf("featured") lcCatalog_visibility = loJResp.StringOf("catalog_visibility") lcDescription = loJResp.StringOf("description") lcShort_description = loJResp.StringOf("short_description") lcSku = loJResp.StringOf("sku") lcPrice = loJResp.StringOf("price") lcRegular_price = loJResp.StringOf("regular_price") lcSale_price = loJResp.StringOf("sale_price") loJResp.DtOf("date_on_sale_from",.F.,loDate_on_sale_from) loJResp.DtOf("date_on_sale_from_gmt",.F.,loDate_on_sale_from_gmt) loJResp.DtOf("date_on_sale_to",.F.,loDate_on_sale_to) loJResp.DtOf("date_on_sale_to_gmt",.F.,loDate_on_sale_to_gmt) lcPrice_html = loJResp.StringOf("price_html") llOn_sale = loJResp.BoolOf("on_sale") llPurchasable = loJResp.BoolOf("purchasable") lnTotal_sales = loJResp.IntOf("total_sales") llVirtual = loJResp.BoolOf("virtual") llDownloadable = loJResp.BoolOf("downloadable") lnDownload_limit = loJResp.IntOf("download_limit") lnDownload_expiry = loJResp.IntOf("download_expiry") lcExternal_url = loJResp.StringOf("external_url") lcButton_text = loJResp.StringOf("button_text") lcTax_status = loJResp.StringOf("tax_status") lcTax_class = loJResp.StringOf("tax_class") llManage_stock = loJResp.BoolOf("manage_stock") lcStock_quantity = loJResp.StringOf("stock_quantity") lcStock_status = loJResp.StringOf("stock_status") lcBackorders = loJResp.StringOf("backorders") llBackorders_allowed = loJResp.BoolOf("backorders_allowed") llBackordered = loJResp.BoolOf("backordered") llSold_individually = loJResp.BoolOf("sold_individually") lcWeight = loJResp.StringOf("weight") lcDimensionsLength = loJResp.StringOf("dimensions.length") lcDimensionsWidth = loJResp.StringOf("dimensions.width") lcDimensionsHeight = loJResp.StringOf("dimensions.height") llShipping_required = loJResp.BoolOf("shipping_required") llShipping_taxable = loJResp.BoolOf("shipping_taxable") lcShipping_class = loJResp.StringOf("shipping_class") lnShipping_class_id = loJResp.IntOf("shipping_class_id") llReviews_allowed = loJResp.BoolOf("reviews_allowed") lcAverage_rating = loJResp.StringOf("average_rating") lnRating_count = loJResp.IntOf("rating_count") lnParent_id = loJResp.IntOf("parent_id") lcPurchase_note = loJResp.StringOf("purchase_note") lnMenu_order = loJResp.IntOf("menu_order") i = 0 lnCount_i = loJResp.SizeOfArray("downloads") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("related_ids") do while i < lnCount_i loJResp.I = i lnIntVal = loJResp.IntOf("related_ids[i]") i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("upsell_ids") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("cross_sell_ids") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("categories") do while i < lnCount_i loJResp.I = i lnId = loJResp.IntOf("categories[i].id") lcName = loJResp.StringOf("categories[i].name") lcSlug = loJResp.StringOf("categories[i].slug") i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("tags") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("images") do while i < lnCount_i loJResp.I = i lnId = loJResp.IntOf("images[i].id") loJResp.DtOf("images[i].date_created",.F.,loDate_created) loJResp.DtOf("images[i].date_created_gmt",.F.,loDate_created_gmt) loJResp.DtOf("images[i].date_modified",.F.,loDate_modified) loJResp.DtOf("images[i].date_modified_gmt",.F.,loDate_modified_gmt) lcSrc = loJResp.StringOf("images[i].src") lcName = loJResp.StringOf("images[i].name") lcAlt = loJResp.StringOf("images[i].alt") i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("attributes") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("default_attributes") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("variations") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("grouped_products") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("meta_data") do while i < lnCount_i loJResp.I = i i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("_links.self") do while i < lnCount_i loJResp.I = i lcHref = loJResp.StringOf("_links.self[i].href") i = i + 1 enddo i = 0 lnCount_i = loJResp.SizeOfArray("_links.collection") do while i < lnCount_i loJResp.I = i lcHref = loJResp.StringOf("_links.collection[i].href") i = i + 1 enddo release loHttp release loJson release loSbResponseBody release loJResp 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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.