React Native
React Native
WooCommerce List All Products
See more WooCommerce Examples
Gets WooCommerce product information in JSON format.Chilkat React Native Downloads
import { DtObj, Http, JsonArray, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
// 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.basicAuth = true;
http.login = 'consumer_key';
http.password = 'consumer_secret';
const sbResponseBody = new StringBuilder();
try {
await http.quickGetSbAsync('https://example.com/wp-json/wc/v3/products', sbResponseBody);
} catch {
console.log(http.lastErrorText);
return;
}
const jarrResp = new JsonArray();
jarrResp.loadSb(sbResponseBody);
jarrResp.emitCompact = false;
console.log('Response Body:');
console.log(jarrResp.emit());
const respStatusCode = http.lastStatus;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(http.lastHeader);
console.log('Failed.');
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\">$</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
const dateCreated = new DtObj();
const dateCreatedGmt = new DtObj();
const dateModified = new DtObj();
const dateModifiedGmt = new DtObj();
const dateOnSaleFrom = new DtObj();
const dateOnSaleFromGmt = new DtObj();
const dateOnSaleTo = new DtObj();
const dateOnSaleToGmt = new DtObj();
let id = 0;
let name = '';
let slug = '';
let permalink = '';
let vType = '';
let status = '';
let catalogVisibility = '';
let description = '';
let shortDescription = '';
let sku = '';
let price = '';
let regularPrice = '';
let salePrice = '';
let priceHtml = '';
let totalSales = 0;
let downloadLimit = 0;
let downloadExpiry = 0;
let externalUrl = '';
let buttonText = '';
let taxStatus = '';
let taxClass = '';
let stockQuantity = '';
let stockStatus = '';
let backorders = '';
let weight = '';
let dimensionsLength = '';
let dimensionsWidth = '';
let dimensionsHeight = '';
let shippingClass = '';
let shippingClassId = 0;
let averageRating = '';
let ratingCount = 0;
let parentId = 0;
let purchaseNote = '';
let menuOrder = 0;
let j = 0;
let countJ = 0;
let intVal = 0;
let src = '';
let alt = '';
let position = 0;
let k = 0;
let countK = 0;
let strVal = '';
let vOption = '';
let href = '';
let i = 0;
const countI = jarrResp.size;
while (i < countI) {
const 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, dateCreated);
json.dtOf('date_created_gmt', false, dateCreatedGmt);
json.dtOf('date_modified', false, dateModified);
json.dtOf('date_modified_gmt', false, dateModifiedGmt);
vType = json.stringOf('type');
status = json.stringOf('status');
json.boolOf('featured');
catalogVisibility = json.stringOf('catalog_visibility');
description = json.stringOf('description');
shortDescription = json.stringOf('short_description');
sku = json.stringOf('sku');
price = json.stringOf('price');
regularPrice = json.stringOf('regular_price');
salePrice = json.stringOf('sale_price');
json.dtOf('date_on_sale_from', false, dateOnSaleFrom);
json.dtOf('date_on_sale_from_gmt', false, dateOnSaleFromGmt);
json.dtOf('date_on_sale_to', false, dateOnSaleTo);
json.dtOf('date_on_sale_to_gmt', false, dateOnSaleToGmt);
priceHtml = json.stringOf('price_html');
json.boolOf('on_sale');
json.boolOf('purchasable');
totalSales = json.intOf('total_sales');
json.boolOf('virtual');
json.boolOf('downloadable');
downloadLimit = json.intOf('download_limit');
downloadExpiry = json.intOf('download_expiry');
externalUrl = json.stringOf('external_url');
buttonText = json.stringOf('button_text');
taxStatus = json.stringOf('tax_status');
taxClass = json.stringOf('tax_class');
json.boolOf('manage_stock');
stockQuantity = json.stringOf('stock_quantity');
stockStatus = json.stringOf('stock_status');
backorders = json.stringOf('backorders');
json.boolOf('backorders_allowed');
json.boolOf('backordered');
json.boolOf('sold_individually');
weight = json.stringOf('weight');
dimensionsLength = json.stringOf('dimensions.length');
dimensionsWidth = json.stringOf('dimensions.width');
dimensionsHeight = json.stringOf('dimensions.height');
json.boolOf('shipping_required');
json.boolOf('shipping_taxable');
shippingClass = json.stringOf('shipping_class');
shippingClassId = json.intOf('shipping_class_id');
json.boolOf('reviews_allowed');
averageRating = json.stringOf('average_rating');
ratingCount = json.intOf('rating_count');
parentId = json.intOf('parent_id');
purchaseNote = json.stringOf('purchase_note');
menuOrder = json.intOf('menu_order');
j = 0;
countJ = json.sizeOfArray('downloads');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('related_ids');
while (j < countJ) {
json.j = j;
intVal = json.intOf('related_ids[j]');
j++;
}
j = 0;
countJ = json.sizeOfArray('upsell_ids');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('cross_sell_ids');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('categories');
while (j < countJ) {
json.j = j;
id = json.intOf('categories[j].id');
name = json.stringOf('categories[j].name');
slug = json.stringOf('categories[j].slug');
j++;
}
j = 0;
countJ = json.sizeOfArray('tags');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('images');
while (j < countJ) {
json.j = j;
id = json.intOf('images[j].id');
json.dtOf('images[j].date_created', false, dateCreated);
json.dtOf('images[j].date_created_gmt', false, dateCreatedGmt);
json.dtOf('images[j].date_modified', false, dateModified);
json.dtOf('images[j].date_modified_gmt', false, dateModifiedGmt);
src = json.stringOf('images[j].src');
name = json.stringOf('images[j].name');
alt = json.stringOf('images[j].alt');
j++;
}
j = 0;
countJ = json.sizeOfArray('attributes');
while (j < countJ) {
json.j = j;
id = json.intOf('attributes[j].id');
name = json.stringOf('attributes[j].name');
position = json.intOf('attributes[j].position');
json.boolOf('attributes[j].visible');
json.boolOf('attributes[j].variation');
k = 0;
countK = json.sizeOfArray('attributes[j].options');
while (k < countK) {
json.k = k;
strVal = json.stringOf('attributes[j].options[k]');
k++;
}
j++;
}
j = 0;
countJ = json.sizeOfArray('default_attributes');
while (j < countJ) {
json.j = j;
id = json.intOf('default_attributes[j].id');
name = json.stringOf('default_attributes[j].name');
vOption = json.stringOf('default_attributes[j].option');
j++;
}
j = 0;
countJ = json.sizeOfArray('variations');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('grouped_products');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('meta_data');
while (j < countJ) {
json.j = j;
j++;
}
j = 0;
countJ = json.sizeOfArray('_links.self');
while (j < countJ) {
json.j = j;
href = json.stringOf('_links.self[j].href');
j++;
}
j = 0;
countJ = json.sizeOfArray('_links.collection');
while (j < countJ) {
json.j = j;
href = json.stringOf('_links.collection[j].href');
j++;
}
i++;
}
}