For the reference implementation we use the XSLT transformers to create accounting entries from the invoice. There has to be a knowledge of if it's a purchase invoice or a sales invoice as they are handeled differently so there is separate transformers for them.
Does the API have a separate interface for purchase / sales invoice? If not, then the application should read from the invoice the buyer and seller ids and make a selection base on which one is the system owner.