Initial api library, base code taken from example code.