Zig
Zig
WiX - Get all Products in a Store
See more WiX Examples
Gets the first page of products in a store.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Implements the following CURL command:
// curl -X POST -H "Content-Type: application/json" \
// -d '{
// "includeVariants": true
// }' https://www.wixapis.com/stores/v1/products/query
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateBool("includeVariants", true) catch {};
http.setAuthToken("ACCESS_TOKEN");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://www.wixapis.com/stores/v1/products/query", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// 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
var id: [:0]const u8 = "";
var name: [:0]const u8 = "";
var slug: [:0]const u8 = "";
var visible: bool = false;
var product_type: [:0]const u8 = "";
var description: [:0]const u8 = "";
var stock_track_inventory: bool = false;
var stock_quantity: i32 = 0;
var stock_in_stock: bool = false;
var price_currency: [:0]const u8 = "";
var price_price: i32 = 0;
var price_discounted_price: i32 = 0;
var price_formatted_price: [:0]const u8 = "";
var price_formatted_discounted_price: [:0]const u8 = "";
var price_data_currency: [:0]const u8 = "";
var price_data_price: i32 = 0;
var price_data_discounted_price: i32 = 0;
var price_data_formatted_price: [:0]const u8 = "";
var price_data_formatted_discounted_price: [:0]const u8 = "";
var manage_variants: bool = false;
var product_page_url_base: [:0]const u8 = "";
var product_page_url_path: [:0]const u8 = "";
var numeric_id: [:0]const u8 = "";
var inventory_item_id: [:0]const u8 = "";
var discount_type: [:0]const u8 = "";
var discount_value: i32 = 0;
var sku: [:0]const u8 = "";
var weight: i32 = 0;
var j: i32 = 0;
var count_j: i32 = 0;
var text: [:0]const u8 = "";
var str_val: [:0]const u8 = "";
_ = j_resp.intOf("metadata.items");
_ = j_resp.intOf("metadata.offset");
_ = j_resp.intOf("totalResults");
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("products");
while (i < count_i) {
j_resp.setI(i);
id = try j_resp.stringOf(alloc, "products[i].id");
name = try j_resp.stringOf(alloc, "products[i].name");
slug = try j_resp.stringOf(alloc, "products[i].slug");
visible = j_resp.boolOf("products[i].visible");
product_type = try j_resp.stringOf(alloc, "products[i].productType");
description = try j_resp.stringOf(alloc, "products[i].description");
stock_track_inventory = j_resp.boolOf("products[i].stock.trackInventory");
stock_quantity = j_resp.intOf("products[i].stock.quantity");
stock_in_stock = j_resp.boolOf("products[i].stock.inStock");
price_currency = try j_resp.stringOf(alloc, "products[i].price.currency");
price_price = j_resp.intOf("products[i].price.price");
price_discounted_price = j_resp.intOf("products[i].price.discountedPrice");
price_formatted_price = try j_resp.stringOf(alloc, "products[i].price.formatted.price");
price_formatted_discounted_price = try j_resp.stringOf(alloc, "products[i].price.formatted.discountedPrice");
price_data_currency = try j_resp.stringOf(alloc, "products[i].priceData.currency");
price_data_price = j_resp.intOf("products[i].priceData.price");
price_data_discounted_price = j_resp.intOf("products[i].priceData.discountedPrice");
price_data_formatted_price = try j_resp.stringOf(alloc, "products[i].priceData.formatted.price");
price_data_formatted_discounted_price = try j_resp.stringOf(alloc, "products[i].priceData.formatted.discountedPrice");
manage_variants = j_resp.boolOf("products[i].manageVariants");
product_page_url_base = try j_resp.stringOf(alloc, "products[i].productPageUrl.base");
product_page_url_path = try j_resp.stringOf(alloc, "products[i].productPageUrl.path");
numeric_id = try j_resp.stringOf(alloc, "products[i].numericId");
inventory_item_id = try j_resp.stringOf(alloc, "products[i].inventoryItemId");
discount_type = try j_resp.stringOf(alloc, "products[i].discount.type");
discount_value = j_resp.intOf("products[i].discount.value");
sku = try j_resp.stringOf(alloc, "products[i].sku");
weight = j_resp.intOf("products[i].weight");
j = 0;
count_j = j_resp.sizeOfArray("products[i].additionalInfoSections");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("products[i].ribbons");
while (j < count_j) {
j_resp.setJ(j);
text = try j_resp.stringOf(alloc, "products[i].ribbons[j].text");
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("products[i].media.items");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("products[i].customTextFields");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("products[i].productOptions");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("products[i].collectionIds");
while (j < count_j) {
j_resp.setJ(j);
str_val = try j_resp.stringOf(alloc, "products[i].collectionIds[j]");
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("products[i].variants");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
i = i + 1;
}
}