API: return 400 and better message for missing entity

Fix issue #380