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
(C) WooCommerce Delete a ProductSee more WooCommerce ExamplesDemonstrates how to delete a product from WooCommerce. For more information, see https://woocommerce.github.io/woocommerce-rest-api-docs/#delete-a-product
#include <C_CkHttp.h> #include <C_CkHttpResponse.h> #include <C_CkStringBuilder.h> #include <C_CkJsonObject.h> #include <C_CkDtObj.h> void ChilkatSample(void) { HCkHttp http; BOOL success; HCkHttpResponse resp; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; HCkDtObj date_created; HCkDtObj date_created_gmt; HCkDtObj date_modified; HCkDtObj date_modified_gmt; HCkDtObj date_on_sale_from; HCkDtObj date_on_sale_from_gmt; HCkDtObj date_on_sale_to; HCkDtObj date_on_sale_to_gmt; int intVal; const char *src; const char *alt; const char *href; int id; const char *name; const char *slug; const char *permalink; const char *v_type; const char *status; BOOL featured; const char *catalog_visibility; const char *description; const char *short_description; const char *sku; const char *price; const char *regular_price; const char *sale_price; const char *price_html; BOOL on_sale; BOOL purchasable; int total_sales; BOOL virtual; BOOL downloadable; int download_limit; int download_expiry; const char *external_url; const char *button_text; const char *tax_status; const char *tax_class; BOOL manage_stock; const char *stock_quantity; const char *stock_status; const char *backorders; BOOL backorders_allowed; BOOL backordered; BOOL sold_individually; const char *weight; const char *dimensionsLength; const char *dimensionsWidth; const char *dimensionsHeight; BOOL shipping_required; BOOL shipping_taxable; const char *shipping_class; int shipping_class_id; BOOL reviews_allowed; const char *average_rating; int rating_count; int parent_id; const char *purchase_note; int menu_order; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_Create(); // 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_putBasicAuth(http,TRUE); CkHttp_putLogin(http,"consumer_key"); CkHttp_putPassword(http,"consumer_secret"); resp = CkHttp_QuickRequest(http,"DELETE","https://example.com/wp-json/wc/v3/products/794?force=true"); if (CkHttp_getLastMethodSuccess(http) == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); return; } sbResponseBody = CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp = CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttpResponse_getStatusCode(resp); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttpResponse_header(resp)); printf("Failed.\n"); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); return; } CkHttpResponse_Dispose(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\">$</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 // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. date_created = CkDtObj_Create(); date_created_gmt = CkDtObj_Create(); date_modified = CkDtObj_Create(); date_modified_gmt = CkDtObj_Create(); date_on_sale_from = CkDtObj_Create(); date_on_sale_from_gmt = CkDtObj_Create(); date_on_sale_to = CkDtObj_Create(); date_on_sale_to_gmt = CkDtObj_Create(); id = CkJsonObject_IntOf(jResp,"id"); name = CkJsonObject_stringOf(jResp,"name"); slug = CkJsonObject_stringOf(jResp,"slug"); permalink = CkJsonObject_stringOf(jResp,"permalink"); CkJsonObject_DtOf(jResp,"date_created",FALSE,date_created); CkJsonObject_DtOf(jResp,"date_created_gmt",FALSE,date_created_gmt); CkJsonObject_DtOf(jResp,"date_modified",FALSE,date_modified); CkJsonObject_DtOf(jResp,"date_modified_gmt",FALSE,date_modified_gmt); v_type = CkJsonObject_stringOf(jResp,"type"); status = CkJsonObject_stringOf(jResp,"status"); featured = CkJsonObject_BoolOf(jResp,"featured"); catalog_visibility = CkJsonObject_stringOf(jResp,"catalog_visibility"); description = CkJsonObject_stringOf(jResp,"description"); short_description = CkJsonObject_stringOf(jResp,"short_description"); sku = CkJsonObject_stringOf(jResp,"sku"); price = CkJsonObject_stringOf(jResp,"price"); regular_price = CkJsonObject_stringOf(jResp,"regular_price"); sale_price = CkJsonObject_stringOf(jResp,"sale_price"); CkJsonObject_DtOf(jResp,"date_on_sale_from",FALSE,date_on_sale_from); CkJsonObject_DtOf(jResp,"date_on_sale_from_gmt",FALSE,date_on_sale_from_gmt); CkJsonObject_DtOf(jResp,"date_on_sale_to",FALSE,date_on_sale_to); CkJsonObject_DtOf(jResp,"date_on_sale_to_gmt",FALSE,date_on_sale_to_gmt); price_html = CkJsonObject_stringOf(jResp,"price_html"); on_sale = CkJsonObject_BoolOf(jResp,"on_sale"); purchasable = CkJsonObject_BoolOf(jResp,"purchasable"); total_sales = CkJsonObject_IntOf(jResp,"total_sales"); virtual = CkJsonObject_BoolOf(jResp,"virtual"); downloadable = CkJsonObject_BoolOf(jResp,"downloadable"); download_limit = CkJsonObject_IntOf(jResp,"download_limit"); download_expiry = CkJsonObject_IntOf(jResp,"download_expiry"); external_url = CkJsonObject_stringOf(jResp,"external_url"); button_text = CkJsonObject_stringOf(jResp,"button_text"); tax_status = CkJsonObject_stringOf(jResp,"tax_status"); tax_class = CkJsonObject_stringOf(jResp,"tax_class"); manage_stock = CkJsonObject_BoolOf(jResp,"manage_stock"); stock_quantity = CkJsonObject_stringOf(jResp,"stock_quantity"); stock_status = CkJsonObject_stringOf(jResp,"stock_status"); backorders = CkJsonObject_stringOf(jResp,"backorders"); backorders_allowed = CkJsonObject_BoolOf(jResp,"backorders_allowed"); backordered = CkJsonObject_BoolOf(jResp,"backordered"); sold_individually = CkJsonObject_BoolOf(jResp,"sold_individually"); weight = CkJsonObject_stringOf(jResp,"weight"); dimensionsLength = CkJsonObject_stringOf(jResp,"dimensions.length"); dimensionsWidth = CkJsonObject_stringOf(jResp,"dimensions.width"); dimensionsHeight = CkJsonObject_stringOf(jResp,"dimensions.height"); shipping_required = CkJsonObject_BoolOf(jResp,"shipping_required"); shipping_taxable = CkJsonObject_BoolOf(jResp,"shipping_taxable"); shipping_class = CkJsonObject_stringOf(jResp,"shipping_class"); shipping_class_id = CkJsonObject_IntOf(jResp,"shipping_class_id"); reviews_allowed = CkJsonObject_BoolOf(jResp,"reviews_allowed"); average_rating = CkJsonObject_stringOf(jResp,"average_rating"); rating_count = CkJsonObject_IntOf(jResp,"rating_count"); parent_id = CkJsonObject_IntOf(jResp,"parent_id"); purchase_note = CkJsonObject_stringOf(jResp,"purchase_note"); menu_order = CkJsonObject_IntOf(jResp,"menu_order"); i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"downloads"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"related_ids"); while (i < count_i) { CkJsonObject_putI(jResp,i); intVal = CkJsonObject_IntOf(jResp,"related_ids[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"upsell_ids"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"cross_sell_ids"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"categories"); while (i < count_i) { CkJsonObject_putI(jResp,i); id = CkJsonObject_IntOf(jResp,"categories[i].id"); name = CkJsonObject_stringOf(jResp,"categories[i].name"); slug = CkJsonObject_stringOf(jResp,"categories[i].slug"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"tags"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"images"); while (i < count_i) { CkJsonObject_putI(jResp,i); id = CkJsonObject_IntOf(jResp,"images[i].id"); CkJsonObject_DtOf(jResp,"images[i].date_created",FALSE,date_created); CkJsonObject_DtOf(jResp,"images[i].date_created_gmt",FALSE,date_created_gmt); CkJsonObject_DtOf(jResp,"images[i].date_modified",FALSE,date_modified); CkJsonObject_DtOf(jResp,"images[i].date_modified_gmt",FALSE,date_modified_gmt); src = CkJsonObject_stringOf(jResp,"images[i].src"); name = CkJsonObject_stringOf(jResp,"images[i].name"); alt = CkJsonObject_stringOf(jResp,"images[i].alt"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"attributes"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"default_attributes"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"variations"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"grouped_products"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"meta_data"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"_links.self"); while (i < count_i) { CkJsonObject_putI(jResp,i); href = CkJsonObject_stringOf(jResp,"_links.self[i].href"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"_links.collection"); while (i < count_i) { CkJsonObject_putI(jResp,i); href = CkJsonObject_stringOf(jResp,"_links.collection[i].href"); i = i + 1; } CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); CkDtObj_Dispose(date_created); CkDtObj_Dispose(date_created_gmt); CkDtObj_Dispose(date_modified); CkDtObj_Dispose(date_modified_gmt); CkDtObj_Dispose(date_on_sale_from); CkDtObj_Dispose(date_on_sale_from_gmt); CkDtObj_Dispose(date_on_sale_to); CkDtObj_Dispose(date_on_sale_to_gmt); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.