api: add unit name validation
Merge pull request #867 from jonboulle/validate_unit_names

API should validate unit names