What happens when the REST server accepts your POST to /api and starts processing it but then, before the response can be sent, the connection drops? This code would see an error from the POST to /api due to a connection failure / timeout, and the transaction rolls back.
Now you've got the /api invoked, but no DB write.