How can I add timesheet entries to an invoice using the API

How can I add timesheet entries to an invoice using the API

When creating an invoice through the Web GUI, I can include unbilled items from my timesheet for specified projects.

How do I do this using the API?

[And is there any chance we could have custom invoice ID formats with per customer numbering so I don't need to do this?]