Objective-C
Objective-C
Trello Create New Board
See more Trello Examples
Create a new board.For more information, see https://developers.trello.com/reference#boardsid
Chilkat Objective-C Downloads
#import <CkoJsonObject.h>
#import <CkoOAuth1.h>
#import <CkoRest.h>
#import <NSString.h>
BOOL success = NO;
// 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.
CkoJsonObject *jsonToken = [[CkoJsonObject alloc] init];
success = [jsonToken LoadFile: @"qa_data/tokens/trello.json"];
CkoOAuth1 *oauth1 = [[CkoOAuth1 alloc] init];
oauth1.ConsumerKey = @"TRELLO_CONSUMER_KEY";
oauth1.ConsumerSecret = @"TRELLO_CONSUMER_SECRET";
oauth1.Token = [jsonToken StringOf: @"oauth_token"];
oauth1.TokenSecret = [jsonToken StringOf: @"oauth_token_secret"];
CkoRest *rest = [[CkoRest alloc] init];
// 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.
BOOL bAutoReconnect = YES;
success = [rest Connect: @"api.trello.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: bAutoReconnect];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
[rest SetAuthOAuth1: oauth1 useQueryParams: NO];
[rest AddQueryParam: @"name" value: @"Football & Rugby"];
[rest AddQueryParam: @"defaultLabels" value: @"true"];
[rest AddQueryParam: @"defaultLists" value: @"true"];
[rest AddQueryParam: @"keepFromSource" value: @"none"];
[rest AddQueryParam: @"prefs_permissionLevel" value: @"private"];
[rest AddQueryParam: @"prefs_voting" value: @"disabled"];
[rest AddQueryParam: @"prefs_comments" value: @"members"];
[rest AddQueryParam: @"prefs_invitations" value: @"members"];
[rest AddQueryParam: @"prefs_selfJoin" value: @"true"];
[rest AddQueryParam: @"prefs_cardCovers" value: @"true"];
[rest AddQueryParam: @"prefs_background" value: @"blue"];
[rest AddQueryParam: @"prefs_cardAging" value: @"regular"];
[rest AddHeader: @"Accept" value: @"application/json"];
NSString *responseBody = [rest FullRequestFormUrlEncoded: @"POST" uriPath: @"/1/boards"];
if (rest.LastMethodSuccess != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
// We should expect a 200 response if successful.
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@",@"Request Header: ");
NSLog(@"%@",rest.LastRequestHeader);
NSLog(@"%@",@"----");
NSLog(@"%@%d",@"Response StatusCode = ",[rest.ResponseStatusCode intValue]);
NSLog(@"%@%@",@"Response StatusLine: ",rest.ResponseStatusText);
NSLog(@"%@",@"Response Header:");
NSLog(@"%@",rest.ResponseHeader);
NSLog(@"%@",responseBody);
return;
}
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json Load: responseBody];
json.EmitCompact = NO;
NSLog(@"%@",[json Emit]);
NSLog(@"%@",@"Success.");
// 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": {}
// }
NSString *id = 0;
NSString *name = 0;
NSString *desc = 0;
NSString *descData = 0;
BOOL closed;
NSString *idOrganization = 0;
BOOL pinned;
NSString *url = 0;
NSString *shortUrl = 0;
NSString *prefsPermissionLevel = 0;
NSString *prefsVoting = 0;
NSString *prefsComments = 0;
NSString *prefsInvitations = 0;
BOOL prefsSelfJoin;
BOOL prefsCardCovers;
NSString *prefsCardAging = 0;
BOOL prefsCalendarFeedEnabled;
NSString *prefsBackground = 0;
NSString *prefsBackgroundImage = 0;
NSString *prefsBackgroundImageScaled = 0;
BOOL prefsBackgroundTile;
NSString *prefsBackgroundBrightness = 0;
NSString *prefsBackgroundColor = 0;
NSString *prefsBackgroundBottomColor = 0;
NSString *prefsBackgroundTopColor = 0;
BOOL prefsCanBePublic;
BOOL prefsCanBeEnterprise;
BOOL prefsCanBeOrg;
BOOL prefsCanBePrivate;
BOOL prefsCanInvite;
NSString *labelNamesGreen = 0;
NSString *labelNamesYellow = 0;
NSString *labelNamesOrange = 0;
NSString *labelNamesRed = 0;
NSString *labelNamesPurple = 0;
NSString *labelNamesBlue = 0;
NSString *labelNamesSky = 0;
NSString *labelNamesLime = 0;
NSString *labelNamesPink = 0;
NSString *labelNamesBlack = 0;
id = [json StringOf: @"id"];
name = [json StringOf: @"name"];
desc = [json StringOf: @"desc"];
descData = [json StringOf: @"descData"];
closed = [json BoolOf: @"closed"];
idOrganization = [json StringOf: @"idOrganization"];
pinned = [json BoolOf: @"pinned"];
url = [json StringOf: @"url"];
shortUrl = [json StringOf: @"shortUrl"];
prefsPermissionLevel = [json StringOf: @"prefs.permissionLevel"];
prefsVoting = [json StringOf: @"prefs.voting"];
prefsComments = [json StringOf: @"prefs.comments"];
prefsInvitations = [json StringOf: @"prefs.invitations"];
prefsSelfJoin = [json BoolOf: @"prefs.selfJoin"];
prefsCardCovers = [json BoolOf: @"prefs.cardCovers"];
prefsCardAging = [json StringOf: @"prefs.cardAging"];
prefsCalendarFeedEnabled = [json BoolOf: @"prefs.calendarFeedEnabled"];
prefsBackground = [json StringOf: @"prefs.background"];
prefsBackgroundImage = [json StringOf: @"prefs.backgroundImage"];
prefsBackgroundImageScaled = [json StringOf: @"prefs.backgroundImageScaled"];
prefsBackgroundTile = [json BoolOf: @"prefs.backgroundTile"];
prefsBackgroundBrightness = [json StringOf: @"prefs.backgroundBrightness"];
prefsBackgroundColor = [json StringOf: @"prefs.backgroundColor"];
prefsBackgroundBottomColor = [json StringOf: @"prefs.backgroundBottomColor"];
prefsBackgroundTopColor = [json StringOf: @"prefs.backgroundTopColor"];
prefsCanBePublic = [json BoolOf: @"prefs.canBePublic"];
prefsCanBeEnterprise = [json BoolOf: @"prefs.canBeEnterprise"];
prefsCanBeOrg = [json BoolOf: @"prefs.canBeOrg"];
prefsCanBePrivate = [json BoolOf: @"prefs.canBePrivate"];
prefsCanInvite = [json BoolOf: @"prefs.canInvite"];
labelNamesGreen = [json StringOf: @"labelNames.green"];
labelNamesYellow = [json StringOf: @"labelNames.yellow"];
labelNamesOrange = [json StringOf: @"labelNames.orange"];
labelNamesRed = [json StringOf: @"labelNames.red"];
labelNamesPurple = [json StringOf: @"labelNames.purple"];
labelNamesBlue = [json StringOf: @"labelNames.blue"];
labelNamesSky = [json StringOf: @"labelNames.sky"];
labelNamesLime = [json StringOf: @"labelNames.lime"];
labelNamesPink = [json StringOf: @"labelNames.pink"];
labelNamesBlack = [json StringOf: @"labelNames.black"];