freshbooks-js :: index

Freshbooks-js

All methods are implemented, see the Freshbooks API. Access a given endpoint, such as system.current via freshbooks.system.current

The project relies on JavaScript generators to provide a simple interface that makes it simple to stitch data together returned from asynchronous API results.

All Freshbooks remote endpoints are implemented as functions and generated dynamically. See the examples for implementation details.

See the Freshbooks API docs for a complete list of available methods.

Simple Example JavaScript

var freshbooks = require("freshbooks-js");
var co = require("co");

// set authentication data
freshbooks.config.update({
	subdomain:"yourname.freshbooks.com",
	token:"token_here"
});

co(function*() {
	var sysdata = yield freshbooks.system.current(null,{basic_auth:true});
	console.log("System data %j", sysdata);
})();

The project, Freshbooks-js, dynamically creates all methods using the Freshbooks.methods list.

Complex Example JavaScript

Create a new category, add an expense to that category, append a string to an expense note, delete the expense.

var freshbooks = require("freshbooks-js");
var co = require("co");

freshbooks.config.update({
	subdomain:"yourname.freshbooks.com",
	token:"token_here"
});

co(function*() {

	var category = yield freshbooks.category.create({
		name:"Super Test"
	},{basic_auth:true});
	var expense = yield.freshbooks.expense.create({
		category_id:data.json.response.category_id,
		amount:"19.95",
		note:"Initial note value"
	},{basic_auth:true});

	var expense_update = yield freshbooks.expense.update({
		expense_id:expense.json.response.expense_id,
		note:expense.json.response.note + "Append this value"
	},{basic_auth:true});

	var expense_get = yield freshbooks.expense.get({
		expense_id:expense.json.response.expense_id		
	},{basic_auth:true});

	var expense_delete = yield freshbooks.expense.delete({
		expense_id:expense.json.response.expense_id			
	},{basic_auth:true});

	return [category,
			expense,
			expense_update,
			expense_get,
			expense_delete];
	
})();

You can find additional examples in the Mocha tests

Freshbooks.Model

Responses from the freshbooks API are wrapped in basic new freshbooks.Model. This provides a basic API to JSON/xml data and status, as well as a .get() convenience method to allow simple access to nested attributes.

var m = new Model({
	req:"outgoing xml string",
	response:{ ... },
	xml:"original xml string",
	json:{
		response:{
			status:"ok",
			client_id:"some_client_id"
		}
	}
});
m.get("client_id");
"some_client_id"
m.status
m.json
m.xml
m.req

Source Code

github.com/gregory80/freshbooks-js

Bugs

You can file issues here

Enjoy

gt