Make API and CLI generate similar domains

As per #1486, it is possible to create a domain that consists of lowercase
alphanumeric characters. Make the API match the CLI's behaviour in this regard.