Forums/Knowledge Base/API

API Basics

Chris Hefley
posted this on July 11, 2011 09:32 pm

Introduction

The LeanKit Kanban API provides a REST-like interface for retrieving data about boards, cards, and recent history, as well as methods for moving cards, adding and updating cards, and deleting cards. ** It doesn't strictly follow the rules of REST. For example we use only the GET and POST HTTP verbs, and the method calls aren't strictly resource-based in every case. But the basic structure and ease of use of a REST API are approximated, without all of the ceremony.

Your Account Url

Each account in LeanKit Kanban has its own unique url. When you sign up for an account, you'll choose a hostname that will form part of the url. If, for example, you choose "myaccount" as your hostname, the url to your LeanKit Kanban account will be http://myaccount.leankitkanban.com. In all the API documentation and examples, we'll use "myaccount" as the example url for your account. When making your API calls, simply replace this part of the url with the url to your LeanKit Kanban account. Example Url:

http://myaccount.leankitkanban.com

Your API Url

Your LeanKit Kanban API url is built based on your account url. So, if your account url is http://myaccount.leankitkanban.com, your LeanKit Kanban API Url would be:

http://myaccount.leankitkanban.com/Kanban/Api/

Each Method in the API will be appended onto your base API Url as shown in the examples below.

Your board Id

Most of the calls to the LeanKit Kanban API are specific to a particular board. In order to make an API call, then, you'll need to determine the BoardId for your board. When viewing your board in your web browser, you can see the board Id in the url. So, for example, if your url when viewing your board is http://myaccount.leankitkanban.com/Boards/Show/101000, then your BoardId is 101000. For most API calls, then your API url would be appended with /Board/{id}, like this:

http://myaccount.leankitkanban.com/Kanban/Api/Board/101000/

Basic Authentication

Authentication for LeanKit Kanban API calls is done using basic authentication. In Basic Authentication the username and password are base64 encoded and appended to the header of each HttpRequest. You could do this manually, base64 encoding the username and password and adding an Authentication header to the request, but most likely you will use a utility provided by whatever programming language you are using to access our API. (See examples below in C# and Python.) For an example of how it works in the browser, try simply opening a web browser and pasting in the url

http://myaccount.leankitkanban.com/Kanban/Api/Board/101000/GetBoard...

(replacing "myaccount" and "101000" with your hostname and your boardId). The browser will pop up a login box requesting your username and password. When you enter your username and password, you should see a response similar to the one in the GetBoardIdentifiers example below (though not formatted as nicely with line breaks and indentations). Adding basic authentication information to the request in c#

var request = (HttpWebRequest)WebRequest.Create(http://myaccount.leankitkanban.com/Kanban/Api/Board/101000/GetBoard...);
request.Method = "GET";
request.Credentials = new NetworkCredential("myusername@mydomain.com", "mypassword");
request.PreAuthenticate = true;

Adding basic authentication information to the request in Python

import httplib2

http = httplib2.Http()
http.add_credentials(username, password)

HTTP GET and HTTP POST

Each LeanKit Kanban method is either an Http GET or an HTTP POST. As an oversimplification, the difference is in how the data is passed to the server. In an Http GET, the request data is passed as part of the url. Whenever you are making a an API call that simply retrieves data based on the parameters in the API url, you will use an Http GET. In an Http POST the request data is passed as part of the request body. Whenever you are making an API call that updates data, like adding or editing a card, you will post the data to be updated as part of the request body, and use an Http POST

ReplyCode, ReplyText, and ReplyData

Each response from a LeanKit Kanban API call is returned in JavaScript Object Notation (JSON). In order for the response/request interpret the payload as JSON, the request will need to set the Content-Type in the request to "application/json".   Each response comes in a standard format with three top-level elements:

{
    "ReplyCode": 200,
    "ReplyText": "Some message about what just happened",
    "ReplyData": [   ]
}

Possible Reply Code values are:

NoData=100,
DataRetrievalSuccess = 200,
DataInsertSuccess = 201,
DataUpdateSuccess = 202,
DataDeleteSuccess = 203,
SystemException = 500,
MinorException = 501,
UserException = 502,
FatalException = 503,
ThrottleWaitResponse = 800,
WipOverrideCommentRequired = 900,
ResendingEmailRequired = 902,
UnauthorizedAccess = 1000

The ReplyCode indicates that you have exceeded the allowable number of calls per minute for that API Method call. The Reply text will contain a short message about the result of the API call, and the ReplyData element will contain a JSON "object" or an array of such "objects" (technically it's just a string...but it represents an object). See examples below for possible ReplyText values and examples of ReplyData.   

 
Topic is closed for comments