My Habits API Documentation v1

The My Habits API is open to all developers to use in their apps, and does not require any special registration or cost. Authentication is done using the user's API token, which is only available to users who have upgraded to My Habits. Your users simply need to provide their API token, and you can access the API on their behalf.

The API is still a work in progress, with more features to be added over time and with demand. If there is a function you would like implemented, contact us at pebble@zevive.com.au so we can discuss your ideas.

Authentication

API requests are authenticated by providing the X-HABITS-TOKEN header with the user API token, which is generated through Account Settings.
X-HABITS-TOKEN: smVM4lNLB3WFJ0xnQT51fc4fKMQ3YiZY

Application Tracking

If your API Application has been given an AppID, you can specify it via the X-HABITS-APPID header. This allows us to track your application usage for debugging and statistics gathering. To register for an AppID, contact us at pebble@zevive.com.au. AppIDs are completely optional.
X-HABITS-APPID: <AppID>

PING

API tokens can be validated by using the /ping command.
GET https://api.my-habits.net/v1/ping
["OK"]

List Habits

All of the Habits the user has configured can be listed with the /habits command.

Searching Habits

Habits can be searched using the search parameter, using a basic fuzzy search.

GET https://api.my-habits.net/v1/habits?search=drink%20water

Sorting Results

Habits can be sorted using the sort parameter. Currently only sorting by next is supported.

GET https://api.my-habits.net/v1/habits?sort=next

Limiting Results

Habits can be limited to a specific number with the limit parameter.

GET https://api.my-habits.net/v1/habits?limit=1

Status

Habits can be filtered to return enabled or disabled habits only by using the enabled parameter. Use enabled=1 for enabled habits and enabled=0 for disabled habits.

GET https://api.my-habits.net/v1/habits?enabled=1
GET https://api.my-habits.net/v1/habits
[
  {
    "id": 23,
    "name": "Put the bin out",
    "enabled": true,
    "type": "streak",
    "frequency": "weekly",
    "description": "Weekly at 21:30 on Sunday.",
    "next_reminder": "2016-04-10T11:30:00+0000",
    "color": "#000000",
    "streak": {
      "current": 1,
      "longest": 21
    }
  },
  {
    "id": 43,
    "name": "Do the washing!",
    "enabled": true,
    "type": "streak",
    "frequency": "daily",
    "description": "Daily at 10:10.",
    "next_reminder": "2016-04-11T00:10:00+0000",
    "color": "#0055FF",
    "streak": {
      "current": 12,
      "longest": 12
    }
  },
  {
    "id": 45,
    "name": "Drink Water",
    "enabled": true,
    "type": "count",
    "frequency": "daily",
    "description": "Start at 09:00...",
    "next_reminder": "2016-04-10T04:23:00+0000",
    "color": "#550055",
    "count": 4
  }
]

View Habit

Specific habits can be viewed by passing the habit ID into the url.

GET https://api.my-habits.net/v1/habits/43
{
  "id": 43,
  "name": "Do the washing!",
  "enabled": true,
  "type": "streak",
  "frequency": "daily",
  "description": "Daily at 10:10.",
  "next_reminder": "2016-04-11T00:10:00+0000",
  "color": "#0055FF",
  "streak": {
    "current": 12,
    "longest": 12
  }
}

Example Code

jQuery:

$.ajax({
    type: "GET",
    url: 'https://api.my-habits.net/v1/habits',
    headers: { 'X-HABITS-TOKEN': '...' },
    success: function (data) {
        console.log(data);
    }
});

XMLHttpRequest:

var url   = 'https://api.my-habits.net/v1/habits';
var token = 'smVM4lNLB3WFJ0xnQT51fc4fKMQ3YiZY';

var request  = new XMLHttpRequest();
request.open('GET', url, true);
request.setRequestHeader('X-HABITS-TOKEN', token);
request.onreadystatechange = function () {
    if (request.readyState == 4) {
        console.log(request.response);
    }
};
request.send();