Zig
Zig
Trello Create New Board
See more Trello Examples
Create a new board.For more information, see https://developers.trello.com/reference#boardsid
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.
// curl --request POST \
// --url 'https://api.trello.com/1/boards?name=name&defaultLabels=true&defaultLists=true&keepFromSource=none&prefs_permissionLevel=private
// &prefs_voting=disabled&prefs_comments=members&prefs_invitations=members&prefs_selfJoin=true&prefs_cardCovers=true&prefs_background=blue&prefs_cardAging=regular'
// 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("name", "Football & Rugby") catch {};
rest.addQueryParam("defaultLabels", "true") catch {};
rest.addQueryParam("defaultLists", "true") catch {};
rest.addQueryParam("keepFromSource", "none") catch {};
rest.addQueryParam("prefs_permissionLevel", "private") catch {};
rest.addQueryParam("prefs_voting", "disabled") catch {};
rest.addQueryParam("prefs_comments", "members") catch {};
rest.addQueryParam("prefs_invitations", "members") catch {};
rest.addQueryParam("prefs_selfJoin", "true") catch {};
rest.addQueryParam("prefs_cardCovers", "true") catch {};
rest.addQueryParam("prefs_background", "blue") catch {};
rest.addQueryParam("prefs_cardAging", "regular") catch {};
rest.addHeader("Accept", "application/json") catch {};
const response_body = rest.fullRequestFormUrlEncoded(alloc, "POST", "/1/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 json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(response_body) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.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
// {
// "id": "5cc606a1e2441a8a8fe3dc48",
// "name": "Football",
// "desc": "",
// "descData": null,
// "closed": false,
// "idOrganization": null,
// "pinned": false,
// "url": "https://trello.com/b/eadpS1Pe/football",
// "shortUrl": "https://trello.com/b/eadpS1Pe",
// "prefs": {
// "permissionLevel": "private",
// "voting": "disabled",
// "comments": "members",
// "invitations": "members",
// "selfJoin": true,
// "cardCovers": true,
// "cardAging": "regular",
// "calendarFeedEnabled": false,
// "background": "blue",
// "backgroundImage": null,
// "backgroundImageScaled": null,
// "backgroundTile": false,
// "backgroundBrightness": "dark",
// "backgroundColor": "#0079BF",
// "backgroundBottomColor": "#0079BF",
// "backgroundTopColor": "#0079BF",
// "canBePublic": true,
// "canBeEnterprise": true,
// "canBeOrg": true,
// "canBePrivate": true,
// "canInvite": true
// },
// "labelNames": {
// "green": "",
// "yellow": "",
// "orange": "",
// "red": "",
// "purple": "",
// "blue": "",
// "sky": "",
// "lime": "",
// "pink": "",
// "black": ""
// },
// "limits": {}
// }
_ = try json.stringOf(alloc, "id");
_ = try json.stringOf(alloc, "name");
_ = try json.stringOf(alloc, "desc");
_ = try json.stringOf(alloc, "descData");
_ = json.boolOf("closed");
_ = try json.stringOf(alloc, "idOrganization");
_ = json.boolOf("pinned");
_ = try json.stringOf(alloc, "url");
_ = try json.stringOf(alloc, "shortUrl");
_ = try json.stringOf(alloc, "prefs.permissionLevel");
_ = try json.stringOf(alloc, "prefs.voting");
_ = try json.stringOf(alloc, "prefs.comments");
_ = try json.stringOf(alloc, "prefs.invitations");
_ = json.boolOf("prefs.selfJoin");
_ = json.boolOf("prefs.cardCovers");
_ = try json.stringOf(alloc, "prefs.cardAging");
_ = json.boolOf("prefs.calendarFeedEnabled");
_ = try json.stringOf(alloc, "prefs.background");
_ = try json.stringOf(alloc, "prefs.backgroundImage");
_ = try json.stringOf(alloc, "prefs.backgroundImageScaled");
_ = json.boolOf("prefs.backgroundTile");
_ = try json.stringOf(alloc, "prefs.backgroundBrightness");
_ = try json.stringOf(alloc, "prefs.backgroundColor");
_ = try json.stringOf(alloc, "prefs.backgroundBottomColor");
_ = try json.stringOf(alloc, "prefs.backgroundTopColor");
_ = json.boolOf("prefs.canBePublic");
_ = json.boolOf("prefs.canBeEnterprise");
_ = json.boolOf("prefs.canBeOrg");
_ = json.boolOf("prefs.canBePrivate");
_ = json.boolOf("prefs.canInvite");
_ = try json.stringOf(alloc, "labelNames.green");
_ = try json.stringOf(alloc, "labelNames.yellow");
_ = try json.stringOf(alloc, "labelNames.orange");
_ = try json.stringOf(alloc, "labelNames.red");
_ = try json.stringOf(alloc, "labelNames.purple");
_ = try json.stringOf(alloc, "labelNames.blue");
_ = try json.stringOf(alloc, "labelNames.sky");
_ = try json.stringOf(alloc, "labelNames.lime");
_ = try json.stringOf(alloc, "labelNames.pink");
_ = try json.stringOf(alloc, "labelNames.black");
}