This is a wiki for starting to sketch version 2 of the Beeminder API. Huge thanks to @insti for help in thinking this through so far.
Here are some principles we may want to adopt:
Wishlist
All queries should return json.
Requests should be able to be made using json.
(This has the advantage of not requiring array data such as road matrices and datapoints to be json encoded and then url encoded as in v1)
e.g.:
curl -X POST -H "application/json" -d '{"slug": "mygoal", "road":[["20150213",null,9]]}' http://api.bmndr.com/etc
Normalised road matrix. [placeholder - Iâll expand on this when I get more time. @insti]
More helpful error messages that give indications about what might be wrong with the submitted data.
This post is a placeholder. Edit at will, including deleting this line when itâs less placeholdy!
Can we agree to keep the option of having a user token that will authenticate just you that can be copied and pasted from any logged in browser? It makes it really easy to write a script to do something quick.
Iâve only using the API to post data, but donât recall running into any issues. The only weirdness was having to URL-encode the JSON. The implicit grant OAuth workflow works well for me, but could confuse some people who are used to the more complicated authorization code grant workflow.
Thoughts from trying to use the API over the last week:
API doesnât seem to export the units for a goal. I mean the human-editable string of what the units are.
diff_since doesnât seem to be honored. Iâm setting diff_since=1423785600 and getting data for February 5.
Concerning that various objects return random extra fields. For example, datapoints contain âcanonicalâ and âdaystampâ which are undocumented. Users have fields like âfitbit_enabledâ (or something like that). Maybe this is just how JSON APIs are, but I grew up on protobuf and I miss being able to know for damn sure what is going to come popping out of the server.
Frustrating that the API seems to be providing the bare minimum for you to âdo it yourselfâ when it comes to calculations rather than enabling quick access to data like âWhat is the value of the goal right now?â or âWhat is the height of the YBR on date [X]?â. Yes itâs all computable, but Iâve got hundreds of lines of python to crunch all this and itâs full of bugs apparently. :-/
Doubly frustrating that the goal time zone and runits are baked into the road data instead of specifying a standard format for the road and letting tz/runits be a transform layer on top of it. If you want to manipulate the road, you have to boil the tz/runits out of it first, and then put them back.
Feature request for wishlist: it would be great if the API included the Access-Control-Allow-Origin header in its responses so browsers wouldnât throw the cross-origin request error when calling the API.
I just tried to use the âcreate a datapointâ endpoint and specified the fields timestamp, value, and comment. It returned the following:
{"errors":{"measured_at":["can't be blank"],"daystamp":["can't be blank"]}}
The documentation doesnât mention a measured_at field anywhere and it also doesnât say that daystamp âcanât be blankâ when specifying a timestamp.
There are several features that are not currently accessible through the API. In particular, I donât think it is possible to change the pledge cap. A new version should have more or less the same features as the web interface.