Delphi ActiveX
Delphi ActiveX
WiX - Get all Products in a Store
See more WiX Examples
Gets the first page of products in a store.Chilkat Delphi ActiveX Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
http: TChilkatHttp;
json: TChilkatJsonObject;
resp: TChilkatHttpResponse;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
id: WideString;
name: WideString;
slug: WideString;
visible: Integer;
productType: WideString;
description: WideString;
stockTrackInventory: Integer;
stockQuantity: Integer;
stockInStock: Integer;
priceCurrency: WideString;
pricePrice: Integer;
priceDiscountedPrice: Integer;
priceFormattedPrice: WideString;
priceFormattedDiscountedPrice: WideString;
priceDataCurrency: WideString;
priceDataPrice: Integer;
priceDataDiscountedPrice: Integer;
priceDataFormattedPrice: WideString;
priceDataFormattedDiscountedPrice: WideString;
manageVariants: Integer;
productPageUrlBase: WideString;
productPageUrlPath: WideString;
numericId: WideString;
inventoryItemId: WideString;
discountType: WideString;
discountValue: Integer;
sku: WideString;
weight: Integer;
j: Integer;
count_j: Integer;
text: WideString;
strVal: WideString;
metadataItems: Integer;
metadataOffset: Integer;
totalResults: Integer;
i: Integer;
count_i: Integer;
begin
success := 0;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := TChilkatHttp.Create(Self);
// Implements the following CURL command:
// curl -X POST -H "Content-Type: application/json" \
// -d '{
// "includeVariants": true
// }' https://www.wixapis.com/stores/v1/products/query
json := TChilkatJsonObject.Create(Self);
json.UpdateBool('includeVariants',1);
http.AuthToken := 'ACCESS_TOKEN';
resp := TChilkatHttpResponse.Create(Self);
success := http.HttpJson('POST','https://www.wixapis.com/stores/v1/products/query',json.ControlInterface,'application/json',resp.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
sbResponseBody := TChilkatStringBuilder.Create(Self);
resp.GetBodySb(sbResponseBody.ControlInterface);
jResp := TChilkatJsonObject.Create(Self);
jResp.LoadSb(sbResponseBody.ControlInterface);
jResp.EmitCompact := 0;
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(jResp.Emit());
respStatusCode := resp.StatusCode;
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(resp.Header);
Memo1.Lines.Add('Failed.');
Exit;
end;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "products": [
// {
// "id": "58fcbb51-ff87-08ff-d97b-646726676e4a",
// "name": "webhook test",
// "slug": "webhook-test",
// "visible": true,
// "productType": "physical",
// "description": "<p>fasdf<\/p>",
// "stock": {
// "trackInventory": true,
// "quantity": 0,
// "inStock": false
// },
// "price": {
// "currency": "ILS",
// "price": 234,
// "discountedPrice": 234,
// "formatted": {
// "price": "234.00 ₪",
// "discountedPrice": "234.00 ₪"
// }
// },
// "priceData": {
// "currency": "ILS",
// "price": 234,
// "discountedPrice": 234,
// "formatted": {
// "price": "234.00 ₪",
// "discountedPrice": "234.00 ₪"
// }
// },
// "additionalInfoSections": [
// ],
// "ribbons": [
// {
// "text": "ribby"
// }
// ],
// "media": {
// "items": [
// ]
// },
// "customTextFields": [
// ],
// "manageVariants": true,
// "productOptions": [
// ],
// "productPageUrl": {
// "base": "https://www.my-website.com/",
// "path": "/product-page/webhook-test"
// },
// "numericId": "1567078000586000",
// "inventoryItemId": "a70344ae-0078-f700-2684-9b98d99891b5",
// "discount": {
// "type": "NONE",
// "value": 0
// },
// "collectionIds": [
// ],
// "variants": [
// ]
// },
// {
// "id": "6507fd67-94e5-10af-73e4-d2167852d5bc",
// "name": "digital product",
// "slug": "digital-product",
// "visible": true,
// "productType": "digital",
// "description": "",
// "sku": "",
// "weight": 0,
// "stock": {
// "trackInventory": false,
// "inStock": true
// },
// "price": {
// "currency": "ILS",
// "price": 123,
// "discountedPrice": 123,
// "formatted": {
// "price": "123.00 ₪",
// "discountedPrice": "123.00 ₪"
// }
// },
// "priceData": {
// "currency": "ILS",
// "price": 123,
// "discountedPrice": 123,
// "formatted": {
// "price": "123.00 ₪",
// "discountedPrice": "123.00 ₪"
// }
// },
// "additionalInfoSections": [
// ],
// "ribbons": [
// ],
// "media": {
// "items": [
// ]
// },
// "customTextFields": [
// ],
// "manageVariants": false,
// "productOptions": [
// ],
// "productPageUrl": {
// "base": "https://www.my-website.com/",
// "path": "/product-page/digital-product"
// },
// "numericId": "1544009414325000",
// "inventoryItemId": "9af80298-6b1a-ef50-8c1b-2de987ad2a43",
// "discount": {
// "type": "NONE",
// "value": 0
// },
// "collectionIds": [
// "ae886d55-2572-eee8-b2c4-13219844b5e4"
// ],
// "variants": [
// ]
// }
// ],
// "metadata": {
// "items": 100,
// "offset": 0
// },
// "totalResults": 2
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
metadataItems := jResp.IntOf('metadata.items');
metadataOffset := jResp.IntOf('metadata.offset');
totalResults := jResp.IntOf('totalResults');
i := 0;
count_i := jResp.SizeOfArray('products');
while i < count_i do
begin
jResp.I := i;
id := jResp.StringOf('products[i].id');
name := jResp.StringOf('products[i].name');
slug := jResp.StringOf('products[i].slug');
visible := jResp.BoolOf('products[i].visible');
productType := jResp.StringOf('products[i].productType');
description := jResp.StringOf('products[i].description');
stockTrackInventory := jResp.BoolOf('products[i].stock.trackInventory');
stockQuantity := jResp.IntOf('products[i].stock.quantity');
stockInStock := jResp.BoolOf('products[i].stock.inStock');
priceCurrency := jResp.StringOf('products[i].price.currency');
pricePrice := jResp.IntOf('products[i].price.price');
priceDiscountedPrice := jResp.IntOf('products[i].price.discountedPrice');
priceFormattedPrice := jResp.StringOf('products[i].price.formatted.price');
priceFormattedDiscountedPrice := jResp.StringOf('products[i].price.formatted.discountedPrice');
priceDataCurrency := jResp.StringOf('products[i].priceData.currency');
priceDataPrice := jResp.IntOf('products[i].priceData.price');
priceDataDiscountedPrice := jResp.IntOf('products[i].priceData.discountedPrice');
priceDataFormattedPrice := jResp.StringOf('products[i].priceData.formatted.price');
priceDataFormattedDiscountedPrice := jResp.StringOf('products[i].priceData.formatted.discountedPrice');
manageVariants := jResp.BoolOf('products[i].manageVariants');
productPageUrlBase := jResp.StringOf('products[i].productPageUrl.base');
productPageUrlPath := jResp.StringOf('products[i].productPageUrl.path');
numericId := jResp.StringOf('products[i].numericId');
inventoryItemId := jResp.StringOf('products[i].inventoryItemId');
discountType := jResp.StringOf('products[i].discount.type');
discountValue := jResp.IntOf('products[i].discount.value');
sku := jResp.StringOf('products[i].sku');
weight := jResp.IntOf('products[i].weight');
j := 0;
count_j := jResp.SizeOfArray('products[i].additionalInfoSections');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('products[i].ribbons');
while j < count_j do
begin
jResp.J := j;
text := jResp.StringOf('products[i].ribbons[j].text');
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('products[i].media.items');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('products[i].customTextFields');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('products[i].productOptions');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('products[i].collectionIds');
while j < count_j do
begin
jResp.J := j;
strVal := jResp.StringOf('products[i].collectionIds[j]');
j := j + 1;
end;
j := 0;
count_j := jResp.SizeOfArray('products[i].variants');
while j < count_j do
begin
jResp.J := j;
j := j + 1;
end;
i := i + 1;
end;
end;