the provided scripts already do "the right thing" so I am not
sure of why you are reimplementing it all, unless you are porting
it to a different language, in which case we would appreciate if
you would contribute it back.
Also, as I said, the implementation of some of the REST API
may change in the future (until I am happy with it and officially
document it :)
so you would be better off using the provided scripts, that
don't expose the implementation.