Sample code for 30+ languages & platforms
Zig

Etsy: Find a Shop's Active Listings

See more Etsy Examples

Finds all active Listings associated with a Shop.

Chilkat Zig Downloads

Zig
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 GET \
    //   https://openapi.etsy.com/v2/shops/shop_id/listings/active?api_key=MY_ETSY_KEYSTRING&limit=2

    const sb_response_body = try chilkat.StringBuilder.init();
    defer sb_response_body.deinit();
    http.quickGetSb("https://openapi.etsy.com/v2/shops/shop_id/listings/active?api_key=MY_ETSY_KEYSTRING&limit=2", sb_response_body) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    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 = http.getLastStatus();
    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 http.getLastHeader(alloc)});
        std.debug.print("Failed.\n", .{});
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "count": 176,
    //   "results": [
    //     {
    //       "listing_id": 720138253,
    //       "state": "active",
    //       "user_id": 17132443,
    //       "category_id": 68890894,
    //       "title": "Star face, Galaxy wall mask, Weird wall mask, Crazy art sculpture,  Original Wall Mask, Wire art sculpture, Wall art sculpture, 3D art",
    //       "description": "The crazy hair says it all. This galaxy face is something every art lover should possess in their collection. The two crazy eyes are so lovable and so in tune with the nose. The thin decorative black  lines emphasize the facial characteristics and the white dots around the face all lead to this gorgeous crazy hair, made of thick metal wire. This unique star face is made of terracotta, ceramic elements,  and sand plaster than it was glued to a wooden board, painted in dark blue. There is a hook on the back for easy hanging. The awesome art piece is perfect for your personal collection or a gift for someone very special.\n\nThe night sky can always be an artist\u2019s inspiration: the countless stars and the vastness can acquire different images and shapes. In this case, this incredible face, filled with numerous stars, emerges from the sky for me. \n  \nTagged: 99heads\n\nThe following materials are used: \n\nTerracotta, ceramic elements, ceramic glaze, ceramic paint, wood, metal wire, glass, sand plaster.\n\nSize:\nHeight: (hair included): 30 cm (11 3\/4")\nWidth: 36cm (14 1\/4 )\nDepth: 6 cm ( 2 1\/2")",
    //       "creation_tsz": 1562700678,
    //       "ending_tsz": 1573331478,
    //       "original_creation_tsz": 1562700678,
    //       "last_modified_tsz": 1562704479,
    //       "price": "160.00",
    //       "currency_code": "USD",
    //       "quantity": 1,
    //       "sku": [
    //       ],
    //       "tags": [
    //         "Crazy art sculpture",
    //         "Wall Ceramic mask",
    //         "Abstract face",
    //         "3D sculpture",
    //         "Wall art Sculpture",
    //         "wire art sculpture",
    //         "wired art",
    //         "modern ceramics",
    //         "wall mask",
    //         "star face",
    //         "galaxy art",
    //         "galaxy wall mask",
    //         "galaxy sculpture"
    //       ],
    //       "category_path": [
    //         "Art",
    //         "Mixed Media"
    //       ],
    //       "category_path_ids": [
    //         68887312,
    //         68890894
    //       ],
    //       "materials": [
    //         "Terracotta",
    //         "ceramic elements",
    //         "ceramic glaze",
    //         "ceramic paint",
    //         "wood",
    //         "metal wire",
    //         "glass",
    //         "sand plaster"
    //       ],
    //       "shop_section_id": 24002839,
    //       "featured_rank": null,
    //       "state_tsz": 1562700678,
    //       "url": "https:\/\/www.etsy.com\/listing\/720138253\/star-face-galaxy-wall-mask-weird-wall?utm_source=chilkattest&utm_medium=api&utm_campaign=api",
    //       "views": 7,
    //       "num_favorers": 1,
    //       "shipping_template_id": null,
    //       "processing_min": 1,
    //       "processing_max": 2,
    //       "who_made": "i_did",
    //       "is_supply": "false",
    //       "when_made": "2010_2019",
    //       "item_weight": null,
    //       "item_weight_unit": "g",
    //       "item_length": null,
    //       "item_width": null,
    //       "item_height": null,
    //       "item_dimensions_unit": "mm",
    //       "is_private": false,
    //       "recipient": null,
    //       "occasion": null,
    //       "style": null,
    //       "non_taxable": false,
    //       "is_customizable": true,
    //       "is_digital": false,
    //       "file_data": "",
    //       "should_auto_renew": false,
    //       "language": "en-US",
    //       "has_variations": false,
    //       "taxonomy_id": 101,
    //       "taxonomy_path": [
    //         "Art & Collectibles",
    //         "Mixed Media & Collage",
    //         "Other Assemblage"
    //       ],
    //       "used_manufacturer": false
    //     },
    //     {
    //       "listing_id": 643852266,
    //       "state": "active",
    //       "user_id": 17132443,
    //       "category_id": 68890894,
    //       "title": "Art gift for couple, Weird art  figures, Ceramic Wall Figurines, Colorful sculptures, 3D wall art, Mixed Media Sculpture by 99heads",
    //       "description": "The faces of the sculptures are made of white clay elements and ceramic glazes. Their bodies are wooden and painted with acrylic paints. Each sculpture has got a hook on the back for you to hang it on the desired place and in the desired arrangement.  These two look amazing next to each other on the wall... they look like good buddies. They are indeed very good friends that want to make your home more comfortable for you and your family or be a surprise gift for someone special :)\n\nMaterials:\nWhite clay, ceramic elements, wood, glass.\n\nTagged by 99heads\n\nSize:\n\nBlue Figure:\nHeight 62cm, width 10cm, depth 3cm\n(Height 24 1\/4" width 4", depth 1 1\/4")\n\nRed Figure:\nHeight 61,5cm, width 9cm, depth 3cm\n(Height 24" width 3 1\/2", depth 1 1\/4")\n\nIf you're interested in having only one of them:\n\nBlue figure:\nhttps:\/\/www.etsy.com\/listing\/609986541\/abstract-ceramic-modern-ceramic-doll\n\nRed figure:\nhttps:\/\/www.etsy.com\/listing\/596145976\/abstract-doll-figure-colorful-sculpture",
    //       "creation_tsz": 1562699323,
    //       "ending_tsz": 1573330123,
    //       "original_creation_tsz": 1541802400,
    //       "last_modified_tsz": 1562699323,
    //       "price": "230.00",
    //       "currency_code": "USD",
    //       "quantity": 1,
    //       "sku": [
    //       ],
    //       "tags": [
    //         "ceramic home decor",
    //         "wall art ceramic",
    //         "abstract ceramic",
    //         "ceramic wall art",
    //         "ceramic sculpture",
    //         "3d wall art",
    //         "Ceramic doll",
    //         "wall art sculpture",
    //         "wall sculpture",
    //         "weird  art figures",
    //         "Art gift for couple",
    //         "colorful sculpture",
    //         "Fun wall hanging art"
    //       ],
    //       "category_path": [
    //         "Art",
    //         "Mixed Media"
    //       ],
    //       "category_path_ids": [
    //         68887312,
    //         68890894
    //       ],
    //       "materials": [
    //         "white clay",
    //         "ceramic elements",
    //         "glass",
    //         "ceramic glazes",
    //         "wood"
    //       ],
    //       "shop_section_id": 24002915,
    //       "featured_rank": null,
    //       "state_tsz": 1541802400,
    //       "url": "https:\/\/www.etsy.com\/listing\/643852266\/art-gift-for-couple-weird-art-figures?utm_source=chilkattest&utm_medium=api&utm_campaign=api",
    //       "views": 143,
    //       "num_favorers": 16,
    //       "shipping_template_id": null,
    //       "processing_min": 1,
    //       "processing_max": 2,
    //       "who_made": "i_did",
    //       "is_supply": "false",
    //       "when_made": "2010_2019",
    //       "item_weight": null,
    //       "item_weight_unit": "g",
    //       "item_length": null,
    //       "item_width": null,
    //       "item_height": null,
    //       "item_dimensions_unit": "mm",
    //       "is_private": false,
    //       "recipient": null,
    //       "occasion": null,
    //       "style": [
    //         "Abstract"
    //       ],
    //       "non_taxable": false,
    //       "is_customizable": true,
    //       "is_digital": false,
    //       "file_data": "",
    //       "should_auto_renew": false,
    //       "language": "en-US",
    //       "has_variations": false,
    //       "taxonomy_id": 101,
    //       "taxonomy_path": [
    //         "Art & Collectibles",
    //         "Mixed Media & Collage",
    //         "Other Assemblage"
    //       ],
    //       "used_manufacturer": false
    //     }
    //   ],
    //   "params": {
    //     "limit": "2",
    //     "offset": 0,
    //     "page": null,
    //     "shop_id": "6634711",
    //     "keywords": null,
    //     "sort_on": "created",
    //     "sort_order": "down",
    //     "min_price": null,
    //     "max_price": null,
    //     "color": null,
    //     "color_accuracy": 0,
    //     "tags": null,
    //     "category": null,
    //     "translate_keywords": "false",
    //     "include_private": 0
    //   },
    //   "type": "Listing",
    //   "pagination": {
    //     "effective_limit": 2,
    //     "effective_offset": 0,
    //     "next_offset": 2,
    //     "effective_page": 1,
    //     "next_page": 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 listing_id: i32 = 0;
    var state: [:0]const u8 = "";
    var user_id: i32 = 0;
    var category_id: i32 = 0;
    var title: [:0]const u8 = "";
    var description: [:0]const u8 = "";
    var creation_tsz: i32 = 0;
    var ending_tsz: i32 = 0;
    var original_creation_tsz: i32 = 0;
    var last_modified_tsz: i32 = 0;
    var price: [:0]const u8 = "";
    var currency_code: [:0]const u8 = "";
    var quantity: i32 = 0;
    var shop_section_id: i32 = 0;
    var featured_rank: [:0]const u8 = "";
    var state_tsz: i32 = 0;
    var url: [:0]const u8 = "";
    var views: i32 = 0;
    var num_favorers: i32 = 0;
    var shipping_template_id: [:0]const u8 = "";
    var processing_min: i32 = 0;
    var processing_max: i32 = 0;
    var who_made: [:0]const u8 = "";
    var is_supply: [:0]const u8 = "";
    var when_made: [:0]const u8 = "";
    var item_weight: [:0]const u8 = "";
    var item_weight_unit: [:0]const u8 = "";
    var item_length: [:0]const u8 = "";
    var item_width: [:0]const u8 = "";
    var item_height: [:0]const u8 = "";
    var item_dimensions_unit: [:0]const u8 = "";
    var is_private: bool = false;
    var recipient: [:0]const u8 = "";
    var occasion: [:0]const u8 = "";
    var style: [:0]const u8 = "";
    var non_taxable: bool = false;
    var is_customizable: bool = false;
    var is_digital: bool = false;
    var file_data: [:0]const u8 = "";
    var should_auto_renew: bool = false;
    var language: [:0]const u8 = "";
    var has_variations: bool = false;
    var taxonomy_id: i32 = 0;
    var used_manufacturer: bool = false;
    var j: i32 = 0;
    var count_j: i32 = 0;
    var str_val: [:0]const u8 = "";
    var int_val: i32 = 0;

    _ = j_resp.intOf("count");
    _ = try j_resp.stringOf(alloc, "params.limit");
    _ = j_resp.intOf("params.offset");
    _ = try j_resp.stringOf(alloc, "params.page");
    _ = try j_resp.stringOf(alloc, "params.shop_id");
    _ = try j_resp.stringOf(alloc, "params.keywords");
    _ = try j_resp.stringOf(alloc, "params.sort_on");
    _ = try j_resp.stringOf(alloc, "params.sort_order");
    _ = try j_resp.stringOf(alloc, "params.min_price");
    _ = try j_resp.stringOf(alloc, "params.max_price");
    _ = try j_resp.stringOf(alloc, "params.color");
    _ = j_resp.intOf("params.color_accuracy");
    _ = try j_resp.stringOf(alloc, "params.tags");
    _ = try j_resp.stringOf(alloc, "params.category");
    _ = try j_resp.stringOf(alloc, "params.translate_keywords");
    _ = j_resp.intOf("params.include_private");
    _ = try j_resp.stringOf(alloc, "type");
    _ = j_resp.intOf("pagination.effective_limit");
    _ = j_resp.intOf("pagination.effective_offset");
    _ = j_resp.intOf("pagination.next_offset");
    _ = j_resp.intOf("pagination.effective_page");
    _ = j_resp.intOf("pagination.next_page");
    var i: i32 = 0;
    const count_i = j_resp.sizeOfArray("results");
    while (i < count_i) {
        j_resp.setI(i);
        listing_id = j_resp.intOf("results[i].listing_id");
        state = try j_resp.stringOf(alloc, "results[i].state");
        user_id = j_resp.intOf("results[i].user_id");
        category_id = j_resp.intOf("results[i].category_id");
        title = try j_resp.stringOf(alloc, "results[i].title");
        description = try j_resp.stringOf(alloc, "results[i].description");
        creation_tsz = j_resp.intOf("results[i].creation_tsz");
        ending_tsz = j_resp.intOf("results[i].ending_tsz");
        original_creation_tsz = j_resp.intOf("results[i].original_creation_tsz");
        last_modified_tsz = j_resp.intOf("results[i].last_modified_tsz");
        price = try j_resp.stringOf(alloc, "results[i].price");
        currency_code = try j_resp.stringOf(alloc, "results[i].currency_code");
        quantity = j_resp.intOf("results[i].quantity");
        shop_section_id = j_resp.intOf("results[i].shop_section_id");
        featured_rank = try j_resp.stringOf(alloc, "results[i].featured_rank");
        state_tsz = j_resp.intOf("results[i].state_tsz");
        url = try j_resp.stringOf(alloc, "results[i].url");
        views = j_resp.intOf("results[i].views");
        num_favorers = j_resp.intOf("results[i].num_favorers");
        shipping_template_id = try j_resp.stringOf(alloc, "results[i].shipping_template_id");
        processing_min = j_resp.intOf("results[i].processing_min");
        processing_max = j_resp.intOf("results[i].processing_max");
        who_made = try j_resp.stringOf(alloc, "results[i].who_made");
        is_supply = try j_resp.stringOf(alloc, "results[i].is_supply");
        when_made = try j_resp.stringOf(alloc, "results[i].when_made");
        item_weight = try j_resp.stringOf(alloc, "results[i].item_weight");
        item_weight_unit = try j_resp.stringOf(alloc, "results[i].item_weight_unit");
        item_length = try j_resp.stringOf(alloc, "results[i].item_length");
        item_width = try j_resp.stringOf(alloc, "results[i].item_width");
        item_height = try j_resp.stringOf(alloc, "results[i].item_height");
        item_dimensions_unit = try j_resp.stringOf(alloc, "results[i].item_dimensions_unit");
        is_private = j_resp.boolOf("results[i].is_private");
        recipient = try j_resp.stringOf(alloc, "results[i].recipient");
        occasion = try j_resp.stringOf(alloc, "results[i].occasion");
        style = try j_resp.stringOf(alloc, "results[i].style");
        non_taxable = j_resp.boolOf("results[i].non_taxable");
        is_customizable = j_resp.boolOf("results[i].is_customizable");
        is_digital = j_resp.boolOf("results[i].is_digital");
        file_data = try j_resp.stringOf(alloc, "results[i].file_data");
        should_auto_renew = j_resp.boolOf("results[i].should_auto_renew");
        language = try j_resp.stringOf(alloc, "results[i].language");
        has_variations = j_resp.boolOf("results[i].has_variations");
        taxonomy_id = j_resp.intOf("results[i].taxonomy_id");
        used_manufacturer = j_resp.boolOf("results[i].used_manufacturer");
        j = 0;
        count_j = j_resp.sizeOfArray("results[i].sku");
        while (j < count_j) {
            j_resp.setJ(j);
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("results[i].tags");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "results[i].tags[j]");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("results[i].category_path");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "results[i].category_path[j]");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("results[i].category_path_ids");
        while (j < count_j) {
            j_resp.setJ(j);
            int_val = j_resp.intOf("results[i].category_path_ids[j]");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("results[i].materials");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "results[i].materials[j]");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("results[i].taxonomy_path");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "results[i].taxonomy_path[j]");
            j = j + 1;
        }

        j = 0;
        count_j = j_resp.sizeOfArray("results[i].style");
        while (j < count_j) {
            j_resp.setJ(j);
            str_val = try j_resp.stringOf(alloc, "results[i].style[j]");
            j = j + 1;
        }

        i = i + 1;
    }
}