If you use 404, how do you know it is that the api was not found or that the record in your database was not found? From your description, i would use 200 ok since your api executed all logic without any … Now, if you consider the application to be just an extension of the server, and the subitem (tree) to be the actual resource, then a 404 response is appropriate:

Explore the significance of rest api 404 errors and learn effective resolution strategies.