There's an easy way to use Process Incoming Bank Files to process the payment.
In the Payment Processing Configuration, set the If no matching Invoice found setting as Create a Prepayment, load the bank file via Incoming Bank File Excel Integration and process the file in the Process Incoming Bank FIles.
It can assign the overpayment part to a prepayment.
To use API, you need to create a pre-processor program to do that. The pre-processor would have to look at the amount of the payment and break it into 2 pieces: 1 to apply to the open invoice and another portion which is the Prepayment.