Sample code for 30+ languages & platforms
Zig

Trello List Member Boards

See more Trello Examples

Lists the boards that the user is a member of.

For more information, see https://developers.trello.com/reference#membersidboards

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.

    // curl --request GET \
    //   --url 'https://api.trello.com/1/members/{member_id}/boards?filter=all&fields=all&lists=none&memberships=none&organization=false&organization_fields=displayName'

    // First get our previously obtained access token.
    const json_token = try chilkat.JsonObject.init();
    defer json_token.deinit();
    try json_token.loadFile("qa_data/tokens/trello.json");

    const oauth1 = try chilkat.OAuth1.init();
    defer oauth1.deinit();
    oauth1.setConsumerKey("TRELLO_CONSUMER_KEY");
    oauth1.setConsumerSecret("TRELLO_CONSUMER_SECRET");
    oauth1.setToken(try json_token.stringOf(alloc, "oauth_token"));
    oauth1.setTokenSecret(try json_token.stringOf(alloc, "oauth_token_secret"));

    const rest = try chilkat.Rest.init();
    defer rest.deinit();

    // Connect using TLS.
    // A single REST object, once connected, can be used for many Trello REST API calls.
    // The auto-reconnect indicates that if the already-established HTTPS connection is closed,
    // then it will be automatically re-established as needed.
    const b_auto_reconnect = true;
    rest.connect("api.trello.com", 443, true, b_auto_reconnect) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    rest.setAuthOAuth1(oauth1, false) catch {};

    rest.addQueryParam("filter", "all") catch {};
    rest.addQueryParam("fields", "all") catch {};
    rest.addQueryParam("lists", "none") catch {};
    rest.addQueryParam("memberships", "normal") catch {};
    rest.addQueryParam("organization", "false") catch {};
    rest.addQueryParam("organization_fields", "name,displayName") catch {};

    rest.addHeader("Accept", "application/json") catch {};

    const response_body = rest.fullRequestNoBody(alloc, "GET", "/1/members/member_id/boards") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // We should expect a 200 response if successful.
    if (rest.getResponseStatusCode() != 200) {
        std.debug.print("Request Header: \n", .{});
        std.debug.print("{s}\n", .{try rest.getLastRequestHeader(alloc)});
        std.debug.print("----\n", .{});
        std.debug.print("Response StatusCode = {d}\n", .{rest.getResponseStatusCode()});
        std.debug.print("Response StatusLine: {s}\n", .{try rest.getResponseStatusText(alloc)});
        std.debug.print("Response Header:\n", .{});
        std.debug.print("{s}\n", .{try rest.getResponseHeader(alloc)});
        std.debug.print("{s}\n", .{response_body});
        return;
    }

    const jarr = try chilkat.JsonArray.init();
    defer jarr.deinit();
    jarr.load(response_body) catch {};
    jarr.setEmitCompact(false);
    std.debug.print("{s}\n", .{try jarr.emit(alloc)});
    std.debug.print("Success.\n", .{});

    // A sample JSON response:
    // (See the parsing code below...)

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    // [
    //   {
    //     "name": "House Projects",
    //     "desc": "",
    //     "descData": null,
    //     "closed": false,
    //     "idOrganization": null,
    //     "limits": null,
    //     "pinned": null,
    //     "shortLink": "j1hkQKKS",
    //     "powerUps": [
    //     ],
    //     "dateLastActivity": null,
    //     "idTags": [
    //     ],
    //     "datePluginDisable": null,
    //     "creationMethod": null,
    //     "ixUpdate": null,
    //     "id": "5cc5fe862106bb8e05aa41e7",
    //     "starred": false,
    //     "url": "https://trello.com/b/j1hkQKKS/house-projects",
    //     "prefs": {
    //       "permissionLevel": "private",
    //       "voting": "disabled",
    //       "comments": "members",
    //       "invitations": "members",
    //       "selfJoin": false,
    //       "cardCovers": true,
    //       "cardAging": "regular",
    //       "calendarFeedEnabled": false,
    //       "background": "5cc344f6ba4cdc5f5cfc7d81",
    //       "backgroundImage": "https://trello-backgrounds.s3.amazonaws.com/SharedBackground/2560x1709/4418c78f2f66d26932fef88aead2aff5/photo-1555985202-12975b0235dc",
    //       "backgroundImageScaled": [
    //         {
    //           "width": 140,
    //           "height": 93,
    //           "url": "https://trello-backgrounds.s3.amazonaws.com/SharedBackground/140x93/0aebced0ac2d8c9c4b9231b1960d28c2/photo-1555985202-12975b0235dc.jpg"
    //         },
    //  ...
    //         {
    //           "width": 2560,
    //           "height": 1709,
    //           "url": "https://trello-backgrounds.s3.amazonaws.com/SharedBackground/2560x1709/4418c78f2f66d26932fef88aead2aff5/photo-1555985202-12975b0235dc"
    //         }
    //       ],
    //       "backgroundTile": false,
    //       "backgroundBrightness": "dark",
    //       "backgroundBottomColor": "#412f23",
    //       "backgroundTopColor": "#a99d97",
    //       "canBePublic": true,
    //       "canBeEnterprise": true,
    //       "canBeOrg": true,
    //       "canBePrivate": true,
    //       "canInvite": true
    //     },
    //     "subscribed": false,
    //     "labelNames": {
    //       "green": "",
    //       "yellow": "",
    //       "orange": "",
    //       "red": "",
    //       "purple": "",
    //       "blue": "",
    //       "sky": "",
    //       "lime": "",
    //       "pink": "",
    //       "black": ""
    //     },
    //     "dateLastView": "2019-04-28T19:28:18.159Z",
    //     "shortUrl": "https://trello.com/b/j1hkQKKS",
    //     "memberships": [
    //       {
    //         "id": "5cc5fe862106bb8e05aa41e8",
    //         "idMember": "5cc5c74067d5215921ca7677",
    //         "memberType": "admin",
    //         "unconfirmed": false,
    //         "deactivated": false
    //       }
    //     ]
    //   },
    //   {
    //     "name": "Vacation Planning",
    //     "desc": "",
    //     "descData": null,
    //     "closed": false,
    //     "idOrganization": null,
    //     "limits": null,
    //     "pinned": null,
    //     "shortLink": "QqIHvQyz",
    //     "powerUps": [
    //     ],
    //     "dateLastActivity": "2019-04-28T15:32:20.134Z",
    //     "idTags": [
    //     ],
    //     "datePluginDisable": null,
    //     "creationMethod": "assisted",
    //     "ixUpdate": null,
    //     "id": "5cc5c783f5b10f8717a6b3d6",
    //     "starred": false,
    //     "url": "https://trello.com/b/QqIHvQyz/vacation-planning",
    //     "prefs": {
    //       "permissionLevel": "private",
    //       "voting": "disabled",
    //       "comments": "members",
    //       "invitations": "members",
    //       "selfJoin": true,
    //       "cardCovers": true,
    //       "cardAging": "regular",
    //       "calendarFeedEnabled": false,
    //       "background": "lime",
    //       "backgroundImage": null,
    //       "backgroundImageScaled": null,
    //       "backgroundTile": false,
    //       "backgroundBrightness": "dark",
    //       "backgroundColor": "#4BBF6B",
    //       "backgroundBottomColor": "#4BBF6B",
    //       "backgroundTopColor": "#4BBF6B",
    //       "canBePublic": true,
    //       "canBeEnterprise": true,
    //       "canBeOrg": true,
    //       "canBePrivate": true,
    //       "canInvite": true
    //     },
    //     "subscribed": false,
    //     "labelNames": {
    //       "green": "",
    //       "yellow": "",
    //       "orange": "",
    //       "red": "",
    //       "purple": "",
    //       "blue": "",
    //       "sky": "",
    //       "lime": "",
    //       "pink": "",
    //       "black": ""
    //     },
    //     "dateLastView": "2019-04-28T19:32:21.009Z",
    //     "shortUrl": "https://trello.com/b/QqIHvQyz",
    //     "memberships": [
    //       {
    //         "id": "5cc5c783f5b10f8717a6b3d7",
    //         "idMember": "5cc5c74067d5215921ca7677",
    //         "memberType": "admin",
    //         "unconfirmed": false,
    //         "deactivated": false
    //       }
    //     ]
    //   }
    // ]

    var i: i32 = 0;
    var name: [:0]const u8 = "";
    var desc: [:0]const u8 = "";
    var desc_data: [:0]const u8 = "";
    var closed: bool = false;
    var id_organization: [:0]const u8 = "";
    var limits: [:0]const u8 = "";
    var pinned: [:0]const u8 = "";
    var short_link: [:0]const u8 = "";
    var date_last_activity: [:0]const u8 = "";
    var date_plugin_disable: [:0]const u8 = "";
    var creation_method: [:0]const u8 = "";
    var ix_update: [:0]const u8 = "";
    var id: [:0]const u8 = "";
    var starred: bool = false;
    var url: [:0]const u8 = "";
    var prefs_permission_level: [:0]const u8 = "";
    var prefs_voting: [:0]const u8 = "";
    var prefs_comments: [:0]const u8 = "";
    var prefs_invitations: [:0]const u8 = "";
    var prefs_self_join: bool = false;
    var prefs_card_covers: bool = false;
    var prefs_card_aging: [:0]const u8 = "";
    var prefs_calendar_feed_enabled: bool = false;
    var prefs_background: [:0]const u8 = "";
    var prefs_background_image: [:0]const u8 = "";
    var prefs_background_tile: bool = false;
    var prefs_background_brightness: [:0]const u8 = "";
    var prefs_background_bottom_color: [:0]const u8 = "";
    var prefs_background_top_color: [:0]const u8 = "";
    var prefs_can_be_public: bool = false;
    var prefs_can_be_enterprise: bool = false;
    var prefs_can_be_org: bool = false;
    var prefs_can_be_private: bool = false;
    var prefs_can_invite: bool = false;
    var subscribed: bool = false;
    var label_names_green: [:0]const u8 = "";
    var label_names_yellow: [:0]const u8 = "";
    var label_names_orange: [:0]const u8 = "";
    var label_names_red: [:0]const u8 = "";
    var label_names_purple: [:0]const u8 = "";
    var label_names_blue: [:0]const u8 = "";
    var label_names_sky: [:0]const u8 = "";
    var label_names_lime: [:0]const u8 = "";
    var label_names_pink: [:0]const u8 = "";
    var label_names_black: [:0]const u8 = "";
    var date_last_view: [:0]const u8 = "";
    var short_url: [:0]const u8 = "";
    var prefs_background_image_scaled: [:0]const u8 = "";
    var prefs_background_color: [:0]const u8 = "";
    var j: i32 = 0;
    var count_j: i32 = 0;
    var width: i32 = 0;
    var height: i32 = 0;
    var id_member: [:0]const u8 = "";
    var member_type: [:0]const u8 = "";
    var unconfirmed: bool = false;
    var deactivated: bool = false;

    i = 0;
    const count_i = jarr.getSize();
    while (i < count_i) {
        const json = try jarr.objectAt(i);
        defer json.deinit();
        name = try json.stringOf(alloc, "name");
        desc = try json.stringOf(alloc, "desc");
        desc_data = try json.stringOf(alloc, "descData");
        closed = json.boolOf("closed");
        id_organization = try json.stringOf(alloc, "idOrganization");
        limits = try json.stringOf(alloc, "limits");
        pinned = try json.stringOf(alloc, "pinned");
        short_link = try json.stringOf(alloc, "shortLink");
        date_last_activity = try json.stringOf(alloc, "dateLastActivity");
        date_plugin_disable = try json.stringOf(alloc, "datePluginDisable");
        creation_method = try json.stringOf(alloc, "creationMethod");
        ix_update = try json.stringOf(alloc, "ixUpdate");
        id = try json.stringOf(alloc, "id");
        starred = json.boolOf("starred");
        url = try json.stringOf(alloc, "url");
        prefs_permission_level = try json.stringOf(alloc, "prefs.permissionLevel");
        prefs_voting = try json.stringOf(alloc, "prefs.voting");
        prefs_comments = try json.stringOf(alloc, "prefs.comments");
        prefs_invitations = try json.stringOf(alloc, "prefs.invitations");
        prefs_self_join = json.boolOf("prefs.selfJoin");
        prefs_card_covers = json.boolOf("prefs.cardCovers");
        prefs_card_aging = try json.stringOf(alloc, "prefs.cardAging");
        prefs_calendar_feed_enabled = json.boolOf("prefs.calendarFeedEnabled");
        prefs_background = try json.stringOf(alloc, "prefs.background");
        prefs_background_image = try json.stringOf(alloc, "prefs.backgroundImage");
        prefs_background_tile = json.boolOf("prefs.backgroundTile");
        prefs_background_brightness = try json.stringOf(alloc, "prefs.backgroundBrightness");
        prefs_background_bottom_color = try json.stringOf(alloc, "prefs.backgroundBottomColor");
        prefs_background_top_color = try json.stringOf(alloc, "prefs.backgroundTopColor");
        prefs_can_be_public = json.boolOf("prefs.canBePublic");
        prefs_can_be_enterprise = json.boolOf("prefs.canBeEnterprise");
        prefs_can_be_org = json.boolOf("prefs.canBeOrg");
        prefs_can_be_private = json.boolOf("prefs.canBePrivate");
        prefs_can_invite = json.boolOf("prefs.canInvite");
        subscribed = json.boolOf("subscribed");
        label_names_green = try json.stringOf(alloc, "labelNames.green");
        label_names_yellow = try json.stringOf(alloc, "labelNames.yellow");
        label_names_orange = try json.stringOf(alloc, "labelNames.orange");
        label_names_red = try json.stringOf(alloc, "labelNames.red");
        label_names_purple = try json.stringOf(alloc, "labelNames.purple");
        label_names_blue = try json.stringOf(alloc, "labelNames.blue");
        label_names_sky = try json.stringOf(alloc, "labelNames.sky");
        label_names_lime = try json.stringOf(alloc, "labelNames.lime");
        label_names_pink = try json.stringOf(alloc, "labelNames.pink");
        label_names_black = try json.stringOf(alloc, "labelNames.black");
        date_last_view = try json.stringOf(alloc, "dateLastView");
        short_url = try json.stringOf(alloc, "shortUrl");
        prefs_background_image_scaled = try json.stringOf(alloc, "prefs.backgroundImageScaled");
        prefs_background_color = try json.stringOf(alloc, "prefs.backgroundColor");
        j = 0;
        count_j = json.sizeOfArray("powerUps");
        while (j < count_j) {
            json.setJ(j);
            // ...
            j = j + 1;
        }

        j = 0;
        count_j = json.sizeOfArray("idTags");
        while (j < count_j) {
            json.setJ(j);
            // ...
            j = j + 1;
        }

        j = 0;
        count_j = json.sizeOfArray("prefs.backgroundImageScaled");
        while (j < count_j) {
            json.setJ(j);
            width = json.intOf("prefs.backgroundImageScaled[j].width");
            height = json.intOf("prefs.backgroundImageScaled[j].height");
            url = try json.stringOf(alloc, "prefs.backgroundImageScaled[j].url");
            j = j + 1;
        }

        j = 0;
        count_j = json.sizeOfArray("memberships");
        while (j < count_j) {
            json.setJ(j);
            id = try json.stringOf(alloc, "memberships[j].id");
            id_member = try json.stringOf(alloc, "memberships[j].idMember");
            member_type = try json.stringOf(alloc, "memberships[j].memberType");
            unconfirmed = json.boolOf("memberships[j].unconfirmed");
            deactivated = json.boolOf("memberships[j].deactivated");
            j = j + 1;
        }

        i = i + 1;
    }
}