Limiting Fields Returned in Payload CMS using REST API #9110
-
I'm using Payload CMS and want to fetch only specific fields from a document when making requests through the REST API. For example, instead of retrieving all fields in a user document, I'd like to limit the response to only the name and email fields. I've tried using the ?fields=name,email query parameter, but it still returns all fields in the response. How can I configure Payload CMS to return only the fields I specify in my REST API requests? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@ab-h-i-n What you want is the select parameter. It's only available in the Payload CMS 3 beta. You can see the documentation here: https://payloadcms.com/docs/beta/queries/select#rest-api |
Beta Was this translation helpful? Give feedback.
Your query is correct. I think you are not using new enough beta.
The select was added in v3.0.0-beta.121
I suggest that you update to latest. Use https://payload-releases-filter.vercel.app/ to view all breaking changes from your current beta to new beta. While in beta it's best to put the complete version in package.json file for all payload packages to make sure you have latest. The beta tag will not update you automatically.