Fields Absent when Limiting Responses with Only in the Contentstack SaaS Headless CMS

This blog post explains one reason why expected fields may be absent when attempting to limit fields returned for entries in the Contentstack SaaS headless CMS.

By default, when you retrieve an entry, the CMS returns all its fields, potentially excluding some system metadata such as workflow state unless explicitly requested. You can use the Contentstack only operator to specify the fields returned, reducing HTTP payloads to increase performance and efficiency.

The only operator translates to an API query string parameter named only[BASE][].

I had assumed that if I wanted to retrieve multiple fields, I would use a comma-separated list of field names. Apparently, this causes Contentstack to look for a single field with an name containing all of those strings and commas, which does not exist.

Rather than using a single comma-separated value, add one instances of the only[BASE][] query string parameter for each field. The Contentstack SDKs likely do this automatically, but I prefer to construct the URLs and HTTP requests, call the HTTPS APIs directly, and process the JSON response myself.

A request for a URL with the following query string parameter would not return the expected fields title and pagedata.

only[BASE][]=title,pagedata

A request for a URL with the following query string parameters returns those fields if they exist.

only[BASE][]=title&only[BASE][]=pagedata

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: