Added API documentation.

Also small change to error handling (now handles 404 errors correctly).