Sample code for 30+ languages & platforms
Unicode C

Trello Create New Board

See more Trello Examples

Create a new board.

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

Chilkat Unicode C Downloads

Unicode C
#include <C_CkJsonObjectW.h>
#include <C_CkOAuth1W.h>
#include <C_CkRestW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJsonObjectW jsonToken;
    HCkOAuth1W oauth1;
    HCkRestW rest;
    BOOL bAutoReconnect;
    const wchar_t *responseBody;
    HCkJsonObjectW json;
    const wchar_t *id;
    const wchar_t *name;
    const wchar_t *desc;
    const wchar_t *descData;
    BOOL closed;
    const wchar_t *idOrganization;
    BOOL pinned;
    const wchar_t *url;
    const wchar_t *shortUrl;
    const wchar_t *prefsPermissionLevel;
    const wchar_t *prefsVoting;
    const wchar_t *prefsComments;
    const wchar_t *prefsInvitations;
    BOOL prefsSelfJoin;
    BOOL prefsCardCovers;
    const wchar_t *prefsCardAging;
    BOOL prefsCalendarFeedEnabled;
    const wchar_t *prefsBackground;
    const wchar_t *prefsBackgroundImage;
    const wchar_t *prefsBackgroundImageScaled;
    BOOL prefsBackgroundTile;
    const wchar_t *prefsBackgroundBrightness;
    const wchar_t *prefsBackgroundColor;
    const wchar_t *prefsBackgroundBottomColor;
    const wchar_t *prefsBackgroundTopColor;
    BOOL prefsCanBePublic;
    BOOL prefsCanBeEnterprise;
    BOOL prefsCanBeOrg;
    BOOL prefsCanBePrivate;
    BOOL prefsCanInvite;
    const wchar_t *labelNamesGreen;
    const wchar_t *labelNamesYellow;
    const wchar_t *labelNamesOrange;
    const wchar_t *labelNamesRed;
    const wchar_t *labelNamesPurple;
    const wchar_t *labelNamesBlue;
    const wchar_t *labelNamesSky;
    const wchar_t *labelNamesLime;
    const wchar_t *labelNamesPink;
    const wchar_t *labelNamesBlack;

    success = FALSE;

    //  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.
    jsonToken = CkJsonObjectW_Create();
    success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/trello.json");

    oauth1 = CkOAuth1W_Create();
    CkOAuth1W_putConsumerKey(oauth1,L"TRELLO_CONSUMER_KEY");
    CkOAuth1W_putConsumerSecret(oauth1,L"TRELLO_CONSUMER_SECRET");
    CkOAuth1W_putToken(oauth1,CkJsonObjectW_stringOf(jsonToken,L"oauth_token"));
    CkOAuth1W_putTokenSecret(oauth1,CkJsonObjectW_stringOf(jsonToken,L"oauth_token_secret"));

    rest = CkRestW_Create();

    //  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.
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.trello.com",443,TRUE,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkJsonObjectW_Dispose(jsonToken);
        CkOAuth1W_Dispose(oauth1);
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthOAuth1(rest,oauth1,FALSE);

    CkRestW_AddQueryParam(rest,L"name",L"Football & Rugby");
    CkRestW_AddQueryParam(rest,L"defaultLabels",L"true");
    CkRestW_AddQueryParam(rest,L"defaultLists",L"true");
    CkRestW_AddQueryParam(rest,L"keepFromSource",L"none");
    CkRestW_AddQueryParam(rest,L"prefs_permissionLevel",L"private");
    CkRestW_AddQueryParam(rest,L"prefs_voting",L"disabled");
    CkRestW_AddQueryParam(rest,L"prefs_comments",L"members");
    CkRestW_AddQueryParam(rest,L"prefs_invitations",L"members");
    CkRestW_AddQueryParam(rest,L"prefs_selfJoin",L"true");
    CkRestW_AddQueryParam(rest,L"prefs_cardCovers",L"true");
    CkRestW_AddQueryParam(rest,L"prefs_background",L"blue");
    CkRestW_AddQueryParam(rest,L"prefs_cardAging",L"regular");

    CkRestW_AddHeader(rest,L"Accept",L"application/json");

    responseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/1/boards");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkJsonObjectW_Dispose(jsonToken);
        CkOAuth1W_Dispose(oauth1);
        CkRestW_Dispose(rest);
        return;
    }

    //  We should expect a 200 response if successful.
    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"Request Header: \n");
        wprintf(L"%s\n",CkRestW_lastRequestHeader(rest));
        wprintf(L"----\n");
        wprintf(L"Response StatusCode = %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response StatusLine: %s\n",CkRestW_responseStatusText(rest));
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"%s\n",responseBody);
        CkJsonObjectW_Dispose(jsonToken);
        CkOAuth1W_Dispose(oauth1);
        CkRestW_Dispose(rest);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_Load(json,responseBody);
    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));
    wprintf(L"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": {}
    //  }

    id = CkJsonObjectW_stringOf(json,L"id");
    name = CkJsonObjectW_stringOf(json,L"name");
    desc = CkJsonObjectW_stringOf(json,L"desc");
    descData = CkJsonObjectW_stringOf(json,L"descData");
    closed = CkJsonObjectW_BoolOf(json,L"closed");
    idOrganization = CkJsonObjectW_stringOf(json,L"idOrganization");
    pinned = CkJsonObjectW_BoolOf(json,L"pinned");
    url = CkJsonObjectW_stringOf(json,L"url");
    shortUrl = CkJsonObjectW_stringOf(json,L"shortUrl");
    prefsPermissionLevel = CkJsonObjectW_stringOf(json,L"prefs.permissionLevel");
    prefsVoting = CkJsonObjectW_stringOf(json,L"prefs.voting");
    prefsComments = CkJsonObjectW_stringOf(json,L"prefs.comments");
    prefsInvitations = CkJsonObjectW_stringOf(json,L"prefs.invitations");
    prefsSelfJoin = CkJsonObjectW_BoolOf(json,L"prefs.selfJoin");
    prefsCardCovers = CkJsonObjectW_BoolOf(json,L"prefs.cardCovers");
    prefsCardAging = CkJsonObjectW_stringOf(json,L"prefs.cardAging");
    prefsCalendarFeedEnabled = CkJsonObjectW_BoolOf(json,L"prefs.calendarFeedEnabled");
    prefsBackground = CkJsonObjectW_stringOf(json,L"prefs.background");
    prefsBackgroundImage = CkJsonObjectW_stringOf(json,L"prefs.backgroundImage");
    prefsBackgroundImageScaled = CkJsonObjectW_stringOf(json,L"prefs.backgroundImageScaled");
    prefsBackgroundTile = CkJsonObjectW_BoolOf(json,L"prefs.backgroundTile");
    prefsBackgroundBrightness = CkJsonObjectW_stringOf(json,L"prefs.backgroundBrightness");
    prefsBackgroundColor = CkJsonObjectW_stringOf(json,L"prefs.backgroundColor");
    prefsBackgroundBottomColor = CkJsonObjectW_stringOf(json,L"prefs.backgroundBottomColor");
    prefsBackgroundTopColor = CkJsonObjectW_stringOf(json,L"prefs.backgroundTopColor");
    prefsCanBePublic = CkJsonObjectW_BoolOf(json,L"prefs.canBePublic");
    prefsCanBeEnterprise = CkJsonObjectW_BoolOf(json,L"prefs.canBeEnterprise");
    prefsCanBeOrg = CkJsonObjectW_BoolOf(json,L"prefs.canBeOrg");
    prefsCanBePrivate = CkJsonObjectW_BoolOf(json,L"prefs.canBePrivate");
    prefsCanInvite = CkJsonObjectW_BoolOf(json,L"prefs.canInvite");
    labelNamesGreen = CkJsonObjectW_stringOf(json,L"labelNames.green");
    labelNamesYellow = CkJsonObjectW_stringOf(json,L"labelNames.yellow");
    labelNamesOrange = CkJsonObjectW_stringOf(json,L"labelNames.orange");
    labelNamesRed = CkJsonObjectW_stringOf(json,L"labelNames.red");
    labelNamesPurple = CkJsonObjectW_stringOf(json,L"labelNames.purple");
    labelNamesBlue = CkJsonObjectW_stringOf(json,L"labelNames.blue");
    labelNamesSky = CkJsonObjectW_stringOf(json,L"labelNames.sky");
    labelNamesLime = CkJsonObjectW_stringOf(json,L"labelNames.lime");
    labelNamesPink = CkJsonObjectW_stringOf(json,L"labelNames.pink");
    labelNamesBlack = CkJsonObjectW_stringOf(json,L"labelNames.black");


    CkJsonObjectW_Dispose(jsonToken);
    CkOAuth1W_Dispose(oauth1);
    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);

    }