Sample code for 30+ languages & platforms
C

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 C Downloads

C
#include <C_CkJsonObject.h>
#include <C_CkOAuth1.h>
#include <C_CkRest.h>
#include <C_CkJsonArray.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJsonObject jsonToken;
    HCkOAuth1 oauth1;
    HCkRest rest;
    BOOL bAutoReconnect;
    const char *responseBody;
    HCkJsonArray jarr;
    int i;
    int count_i;
    HCkJsonObject json;
    const char *name;
    const char *desc;
    const char *descData;
    BOOL closed;
    const char *idOrganization;
    const char *limits;
    const char *pinned;
    const char *shortLink;
    const char *dateLastActivity;
    const char *datePluginDisable;
    const char *creationMethod;
    const char *ixUpdate;
    const char *id;
    BOOL starred;
    const char *url;
    const char *prefsPermissionLevel;
    const char *prefsVoting;
    const char *prefsComments;
    const char *prefsInvitations;
    BOOL prefsSelfJoin;
    BOOL prefsCardCovers;
    const char *prefsCardAging;
    BOOL prefsCalendarFeedEnabled;
    const char *prefsBackground;
    const char *prefsBackgroundImage;
    BOOL prefsBackgroundTile;
    const char *prefsBackgroundBrightness;
    const char *prefsBackgroundBottomColor;
    const char *prefsBackgroundTopColor;
    BOOL prefsCanBePublic;
    BOOL prefsCanBeEnterprise;
    BOOL prefsCanBeOrg;
    BOOL prefsCanBePrivate;
    BOOL prefsCanInvite;
    BOOL subscribed;
    const char *labelNamesGreen;
    const char *labelNamesYellow;
    const char *labelNamesOrange;
    const char *labelNamesRed;
    const char *labelNamesPurple;
    const char *labelNamesBlue;
    const char *labelNamesSky;
    const char *labelNamesLime;
    const char *labelNamesPink;
    const char *labelNamesBlack;
    const char *dateLastView;
    const char *shortUrl;
    const char *prefsBackgroundImageScaled;
    const char *prefsBackgroundColor;
    int j;
    int count_j;
    int width;
    int height;
    const char *idMember;
    const char *memberType;
    BOOL unconfirmed;
    BOOL deactivated;

    success = FALSE;

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

    oauth1 = CkOAuth1_Create();
    CkOAuth1_putConsumerKey(oauth1,"TRELLO_CONSUMER_KEY");
    CkOAuth1_putConsumerSecret(oauth1,"TRELLO_CONSUMER_SECRET");
    CkOAuth1_putToken(oauth1,CkJsonObject_stringOf(jsonToken,"oauth_token"));
    CkOAuth1_putTokenSecret(oauth1,CkJsonObject_stringOf(jsonToken,"oauth_token_secret"));

    rest = CkRest_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 = CkRest_Connect(rest,"api.trello.com",443,TRUE,bAutoReconnect);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkJsonObject_Dispose(jsonToken);
        CkOAuth1_Dispose(oauth1);
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthOAuth1(rest,oauth1,FALSE);

    CkRest_AddQueryParam(rest,"filter","all");
    CkRest_AddQueryParam(rest,"fields","all");
    CkRest_AddQueryParam(rest,"lists","none");
    CkRest_AddQueryParam(rest,"memberships","normal");
    CkRest_AddQueryParam(rest,"organization","false");
    CkRest_AddQueryParam(rest,"organization_fields","name,displayName");

    CkRest_AddHeader(rest,"Accept","application/json");

    responseBody = CkRest_fullRequestNoBody(rest,"GET","/1/members/member_id/boards");
    if (CkRest_getLastMethodSuccess(rest) != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkJsonObject_Dispose(jsonToken);
        CkOAuth1_Dispose(oauth1);
        CkRest_Dispose(rest);
        return;
    }

    // We should expect a 200 response if successful.
    if (CkRest_getResponseStatusCode(rest) != 200) {
        printf("Request Header: \n");
        printf("%s\n",CkRest_lastRequestHeader(rest));
        printf("----\n");
        printf("Response StatusCode = %d\n",CkRest_getResponseStatusCode(rest));
        printf("Response StatusLine: %s\n",CkRest_responseStatusText(rest));
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("%s\n",responseBody);
        CkJsonObject_Dispose(jsonToken);
        CkOAuth1_Dispose(oauth1);
        CkRest_Dispose(rest);
        return;
    }

    jarr = CkJsonArray_Create();
    CkJsonArray_Load(jarr,responseBody);
    CkJsonArray_putEmitCompact(jarr,FALSE);
    printf("%s\n",CkJsonArray_emit(jarr));
    printf("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
    //       }
    //     ]
    //   }
    // ]

    i = 0;
    count_i = CkJsonArray_getSize(jarr);
    while (i < count_i) {
        json = CkJsonArray_ObjectAt(jarr,i);
        name = CkJsonObject_stringOf(json,"name");
        desc = CkJsonObject_stringOf(json,"desc");
        descData = CkJsonObject_stringOf(json,"descData");
        closed = CkJsonObject_BoolOf(json,"closed");
        idOrganization = CkJsonObject_stringOf(json,"idOrganization");
        limits = CkJsonObject_stringOf(json,"limits");
        pinned = CkJsonObject_stringOf(json,"pinned");
        shortLink = CkJsonObject_stringOf(json,"shortLink");
        dateLastActivity = CkJsonObject_stringOf(json,"dateLastActivity");
        datePluginDisable = CkJsonObject_stringOf(json,"datePluginDisable");
        creationMethod = CkJsonObject_stringOf(json,"creationMethod");
        ixUpdate = CkJsonObject_stringOf(json,"ixUpdate");
        id = CkJsonObject_stringOf(json,"id");
        starred = CkJsonObject_BoolOf(json,"starred");
        url = CkJsonObject_stringOf(json,"url");
        prefsPermissionLevel = CkJsonObject_stringOf(json,"prefs.permissionLevel");
        prefsVoting = CkJsonObject_stringOf(json,"prefs.voting");
        prefsComments = CkJsonObject_stringOf(json,"prefs.comments");
        prefsInvitations = CkJsonObject_stringOf(json,"prefs.invitations");
        prefsSelfJoin = CkJsonObject_BoolOf(json,"prefs.selfJoin");
        prefsCardCovers = CkJsonObject_BoolOf(json,"prefs.cardCovers");
        prefsCardAging = CkJsonObject_stringOf(json,"prefs.cardAging");
        prefsCalendarFeedEnabled = CkJsonObject_BoolOf(json,"prefs.calendarFeedEnabled");
        prefsBackground = CkJsonObject_stringOf(json,"prefs.background");
        prefsBackgroundImage = CkJsonObject_stringOf(json,"prefs.backgroundImage");
        prefsBackgroundTile = CkJsonObject_BoolOf(json,"prefs.backgroundTile");
        prefsBackgroundBrightness = CkJsonObject_stringOf(json,"prefs.backgroundBrightness");
        prefsBackgroundBottomColor = CkJsonObject_stringOf(json,"prefs.backgroundBottomColor");
        prefsBackgroundTopColor = CkJsonObject_stringOf(json,"prefs.backgroundTopColor");
        prefsCanBePublic = CkJsonObject_BoolOf(json,"prefs.canBePublic");
        prefsCanBeEnterprise = CkJsonObject_BoolOf(json,"prefs.canBeEnterprise");
        prefsCanBeOrg = CkJsonObject_BoolOf(json,"prefs.canBeOrg");
        prefsCanBePrivate = CkJsonObject_BoolOf(json,"prefs.canBePrivate");
        prefsCanInvite = CkJsonObject_BoolOf(json,"prefs.canInvite");
        subscribed = CkJsonObject_BoolOf(json,"subscribed");
        labelNamesGreen = CkJsonObject_stringOf(json,"labelNames.green");
        labelNamesYellow = CkJsonObject_stringOf(json,"labelNames.yellow");
        labelNamesOrange = CkJsonObject_stringOf(json,"labelNames.orange");
        labelNamesRed = CkJsonObject_stringOf(json,"labelNames.red");
        labelNamesPurple = CkJsonObject_stringOf(json,"labelNames.purple");
        labelNamesBlue = CkJsonObject_stringOf(json,"labelNames.blue");
        labelNamesSky = CkJsonObject_stringOf(json,"labelNames.sky");
        labelNamesLime = CkJsonObject_stringOf(json,"labelNames.lime");
        labelNamesPink = CkJsonObject_stringOf(json,"labelNames.pink");
        labelNamesBlack = CkJsonObject_stringOf(json,"labelNames.black");
        dateLastView = CkJsonObject_stringOf(json,"dateLastView");
        shortUrl = CkJsonObject_stringOf(json,"shortUrl");
        prefsBackgroundImageScaled = CkJsonObject_stringOf(json,"prefs.backgroundImageScaled");
        prefsBackgroundColor = CkJsonObject_stringOf(json,"prefs.backgroundColor");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(json,"powerUps");
        while (j < count_j) {
            CkJsonObject_putJ(json,j);
            // ...
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(json,"idTags");
        while (j < count_j) {
            CkJsonObject_putJ(json,j);
            // ...
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(json,"prefs.backgroundImageScaled");
        while (j < count_j) {
            CkJsonObject_putJ(json,j);
            width = CkJsonObject_IntOf(json,"prefs.backgroundImageScaled[j].width");
            height = CkJsonObject_IntOf(json,"prefs.backgroundImageScaled[j].height");
            url = CkJsonObject_stringOf(json,"prefs.backgroundImageScaled[j].url");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObject_SizeOfArray(json,"memberships");
        while (j < count_j) {
            CkJsonObject_putJ(json,j);
            id = CkJsonObject_stringOf(json,"memberships[j].id");
            idMember = CkJsonObject_stringOf(json,"memberships[j].idMember");
            memberType = CkJsonObject_stringOf(json,"memberships[j].memberType");
            unconfirmed = CkJsonObject_BoolOf(json,"memberships[j].unconfirmed");
            deactivated = CkJsonObject_BoolOf(json,"memberships[j].deactivated");
            j = j + 1;
        }

        CkJsonObject_Dispose(json);
        i = i + 1;
    }



    CkJsonObject_Dispose(jsonToken);
    CkOAuth1_Dispose(oauth1);
    CkRest_Dispose(rest);
    CkJsonArray_Dispose(jarr);

    }