Java
Chilkat2 Java
Trello Create New Board
See more Trello Examples
Create a new board.For more information, see https://developers.trello.com/reference#boardsid
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.OAuth1;
import com.chilkatsoft.chilkat2.Rest;
public class ChilkatExample {
public static void main(String[] args) {
// 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.
JsonObject jsonToken = new JsonObject();
jsonToken.loadFile("qa_data/tokens/trello.json");
OAuth1 oauth1 = new OAuth1();
oauth1.setConsumerKey("TRELLO_CONSUMER_KEY");
oauth1.setConsumerSecret("TRELLO_CONSUMER_SECRET");
oauth1.setToken(jsonToken.stringOf("oauth_token"));
oauth1.setTokenSecret(jsonToken.stringOf("oauth_token_secret"));
Rest rest = new Rest();
// 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.
boolean bAutoReconnect = true;
String responseBody;
try {
rest.connect("api.trello.com", 443, true, bAutoReconnect);
rest.setAuthOAuth1(oauth1, false);
rest.addQueryParam("name", "Football & Rugby");
rest.addQueryParam("defaultLabels", "true");
rest.addQueryParam("defaultLists", "true");
rest.addQueryParam("keepFromSource", "none");
rest.addQueryParam("prefs_permissionLevel", "private");
rest.addQueryParam("prefs_voting", "disabled");
rest.addQueryParam("prefs_comments", "members");
rest.addQueryParam("prefs_invitations", "members");
rest.addQueryParam("prefs_selfJoin", "true");
rest.addQueryParam("prefs_cardCovers", "true");
rest.addQueryParam("prefs_background", "blue");
rest.addQueryParam("prefs_cardAging", "regular");
rest.addHeader("Accept", "application/json");
responseBody = rest.fullRequestFormUrlEncoded("POST", "/1/boards");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// We should expect a 200 response if successful.
if (rest.getResponseStatusCode() != 200) {
System.out.println("Request Header: ");
System.out.println(rest.getLastRequestHeader());
System.out.println("----");
System.out.println("Response StatusCode = " + rest.getResponseStatusCode());
System.out.println("Response StatusLine: " + rest.getResponseStatusText());
System.out.println("Response Header:");
System.out.println(rest.getResponseHeader());
System.out.println(responseBody);
return;
}
JsonObject json = new JsonObject();
json.load(responseBody);
json.setEmitCompact(false);
System.out.println(json.emit());
System.out.println("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": {}
// }
String id = json.stringOf("id");
String name = json.stringOf("name");
String desc = json.stringOf("desc");
String descData = json.stringOf("descData");
boolean closed = json.boolOf("closed");
String idOrganization = json.stringOf("idOrganization");
boolean pinned = json.boolOf("pinned");
String url = json.stringOf("url");
String shortUrl = json.stringOf("shortUrl");
String prefsPermissionLevel = json.stringOf("prefs.permissionLevel");
String prefsVoting = json.stringOf("prefs.voting");
String prefsComments = json.stringOf("prefs.comments");
String prefsInvitations = json.stringOf("prefs.invitations");
boolean prefsSelfJoin = json.boolOf("prefs.selfJoin");
boolean prefsCardCovers = json.boolOf("prefs.cardCovers");
String prefsCardAging = json.stringOf("prefs.cardAging");
boolean prefsCalendarFeedEnabled = json.boolOf("prefs.calendarFeedEnabled");
String prefsBackground = json.stringOf("prefs.background");
String prefsBackgroundImage = json.stringOf("prefs.backgroundImage");
String prefsBackgroundImageScaled = json.stringOf("prefs.backgroundImageScaled");
boolean prefsBackgroundTile = json.boolOf("prefs.backgroundTile");
String prefsBackgroundBrightness = json.stringOf("prefs.backgroundBrightness");
String prefsBackgroundColor = json.stringOf("prefs.backgroundColor");
String prefsBackgroundBottomColor = json.stringOf("prefs.backgroundBottomColor");
String prefsBackgroundTopColor = json.stringOf("prefs.backgroundTopColor");
boolean prefsCanBePublic = json.boolOf("prefs.canBePublic");
boolean prefsCanBeEnterprise = json.boolOf("prefs.canBeEnterprise");
boolean prefsCanBeOrg = json.boolOf("prefs.canBeOrg");
boolean prefsCanBePrivate = json.boolOf("prefs.canBePrivate");
boolean prefsCanInvite = json.boolOf("prefs.canInvite");
String labelNamesGreen = json.stringOf("labelNames.green");
String labelNamesYellow = json.stringOf("labelNames.yellow");
String labelNamesOrange = json.stringOf("labelNames.orange");
String labelNamesRed = json.stringOf("labelNames.red");
String labelNamesPurple = json.stringOf("labelNames.purple");
String labelNamesBlue = json.stringOf("labelNames.blue");
String labelNamesSky = json.stringOf("labelNames.sky");
String labelNamesLime = json.stringOf("labelNames.lime");
String labelNamesPink = json.stringOf("labelNames.pink");
String labelNamesBlack = json.stringOf("labelNames.black");
}
}