Thanks for asking your question on the forum. To help you best, it would be nice if you can share some more details.
Are you trying to use the Mendix API from a Mendix application? In that case, it is always preferred to use as much Mendix logic as possible. Potentially, you can achieve your goal by using a regular retrieve, a nanoflow, or potentially a JS action.
If you are trying to use this from a non-Mendix app, I would suggest to setup a REST interface. This will give you more control regarding access and exposed data.
Looking forward to your additional details. Hopefully this helps already.