Skip to main content

Pinned data (data_sources)

This page shows the JSON behind pinned entries and pinned queries: the data_sources items that declare them, how a query's filters are stored, and the bindings that read them. You need it when you write a composition with the Studio API, or read one that Studio saved.

The examples use the Blog project: the Blog post and Author content types, and the author entry Priya.

The data_sources array​

A contentstack or contentstack_queries binding reads from data_sources. The Studio API takes data_sources as an array and stores it as a JSON string. A string or any other value that isn't an array fails with data_sources_not_array.

[
{
"uid": "contentstack",
"data": [{ "uid": "blt9f8e7d6c5b4a3210", "_content_type_uid": "author" }]
},
{
"uid": "contentstack_queries",
"data": [
{
"uid": "latest-posts",
"name": "Latest posts",
"spec": {
"contentType": "blog_post",
"sourceType": "content_type",
"query": {},
"params": { "limit": 3, "desc": "created_at" }
}
}
]
}
]
  • The SDK reads a pinned entry from dataSources.contentstack under the key <content type uid>:<entry uid>.
  • An item's uid is template, contentstack, contentstack_queries or external_data. The API rejects any other, including queries, and rejects two items with the same uid.
  • Each pinned entry needs both uid and _content_type_uid. The API rejects a pinned entry with an old references list, because it works out reference paths itself.
  • A query spec has four fields: contentType, sourceType, query and params. sourceType defaults to content_type, and Studio writes only that value.
  • In params, limit, skip, asc and desc map to the Delivery API. desc and asc take a field UID.
  • The SDK sends params.include as reference includes, but Studio removes include, only and except from the filters you type.
  • Studio sets a new query's uid to its name in lowercase with spaces changed to hyphens, and keeps it when you rename the query.
  • A query that isn't in data_sources never runs, so a binding to its queryUID shows the prop's default. The API rejects that binding with binding_query_not_declared.
  • A contentstack binding to an entry that isn't pinned in data_sources gets the warning binding_pinned_entry_not_declared. The API then adds the entry to the contentstack item, so the entry's references are fetched.
  • The SDK skips a query whose spec has no contentType, with no error. The API rejects it with query_spec_invalid, and rejects two queries with the same uid.
  • The content type of each pinned entry and query must exist in the stack.
  • A failed query request returns { entries: [], count: 0 }, so the list is empty and no error shows.
  • A pinned entry the Delivery API doesn't return leaves its bindings on the prop's default.
  • Pinned Queries need @contentstack/studio-react 1.3.0 or later, which brings @contentstack/studio-client 1.5.0.

Where the filters go​

The YAML you type in Input Filters splits into two parts of spec. Its query key becomes spec.query, and its params key becomes spec.params.

A variable, such as {{url.params.topic}} or {{now - 30 days}}, is stored as that exact string. Studio doesn't work out its value when you save. The SDK replaces it each time the composition renders, so the list follows the page URL and the date.

This filter, typed in Studio:

query:
taxonomies.topic:
$in:
- "{{url.params.topic}}"
created_at:
$gte: "{{now - 30 days}}"
params:
limit: 3
desc: created_at

is stored as this spec:

{
"contentType": "blog_post",
"sourceType": "content_type",
"query": {
"taxonomies.topic": { "$in": ["{{url.params.topic}}"] },
"created_at": { "$gte": "{{now - 30 days}}" }
},
"params": { "limit": 3, "desc": "created_at" }
}
  • Write a variable as a whole string value, with the braces. The SDK replaces only a value that starts with {{.
  • A variable the SDK doesn't know is sent as typed, and the SDK logs Unknown expression in the console.
  • On a server-rendered route, url.params is empty unless you pass the request's query string. See The page URL.
  • For every variable and operator, see Query Input Filters.

Bind a prop to a pinned entry​

A contentstack binding names the entry by uid and _content_type_uid, and the field by path. This header shows the pinned author's name.

{
"uid": "author_heading",
"type": "header",
"attrs": {},
"metadata": {},
"props": {
"text": {
"type": "string",
"binding": {
"type": "contentstack",
"value": {
"uid": "blt9f8e7d6c5b4a3210",
"_content_type_uid": "author",
"path": { "title": {} }
}
}
}
},
"slots": {},
"styles": {}
}

Repeat a card for each query result​

A contentstack_queries binding reads an object with entries and count, not a bare list. A Repeater over a query reads its items from path: { "entries": {} }. path: {} works too. Each card reads the current post with a repeater binding.

{
"uid": "topic_posts_repeater",
"type": "repeater",
"attrs": {},
"metadata": { "mode": "preview" },
"props": {
"items": {
"type": "array",
"binding": {
"type": "contentstack_queries",
"value": { "queryUID": "topic-posts", "path": { "entries": {} } }
}
},
"children": { "type": "slot", "slot": "items_slot" }
},
"slots": {
"items_slot": [
{
"uid": "topic_post_card",
"type": "PostCard",
"attrs": {},
"metadata": {},
"props": {
"title": {
"type": "string",
"binding": {
"type": "repeater",
"value": { "repeaterUID": "topic_posts_repeater", "path": { "title": {} } }
}
}
},
"slots": {},
"styles": {}
}
]
},
"styles": {}
}

A Section with a pinned entry and a filtered query​

This Section, Topic posts, shows Priya's name and the 3 newest posts of the last 30 days on the topic in the page URL. It has no linked schema, so it reads only its own pinned data. Send it to the /sections route as in Create a section and a template with the API.

{
"title": "Topic posts",
"composable_uid": "topic_posts",
"ui": {
"uid": "topic_posts_root",
"attrs": {},
"type": "page",
"metadata": {},
"props": {
"children": { "type": "slot", "slot": "body_slot" }
},
"slots": {
"body_slot": [
{
"uid": "author_heading",
"type": "header",
"attrs": {},
"metadata": {},
"props": {
"text": {
"type": "string",
"binding": {
"type": "contentstack",
"value": {
"uid": "blt9f8e7d6c5b4a3210",
"_content_type_uid": "author",
"path": { "title": {} }
}
}
}
},
"slots": {},
"styles": {}
},
{
"uid": "topic_posts_repeater",
"type": "repeater",
"attrs": {},
"metadata": { "mode": "preview" },
"props": {
"items": {
"type": "array",
"binding": {
"type": "contentstack_queries",
"value": { "queryUID": "topic-posts", "path": { "entries": {} } }
}
},
"children": { "type": "slot", "slot": "items_slot" }
},
"slots": {
"items_slot": [
{
"uid": "topic_post_card",
"type": "PostCard",
"attrs": {},
"metadata": {},
"props": {
"title": {
"type": "string",
"binding": {
"type": "repeater",
"value": { "repeaterUID": "topic_posts_repeater", "path": { "title": {} } }
}
}
},
"slots": {},
"styles": {}
}
]
},
"styles": {}
}
]
},
"styles": {}
},
"data_sources": [
{
"uid": "contentstack",
"data": [{ "uid": "blt9f8e7d6c5b4a3210", "_content_type_uid": "author" }]
},
{
"uid": "contentstack_queries",
"data": [
{
"uid": "topic-posts",
"name": "Topic posts",
"spec": {
"contentType": "blog_post",
"sourceType": "content_type",
"query": {
"taxonomies.topic": { "$in": ["{{url.params.topic}}"] },
"created_at": { "$gte": "{{now - 30 days}}" }
},
"params": { "limit": 3, "desc": "created_at" }
}
}
]
}
],
"static_value": {
"text": [],
"href": [],
"imageurl": []
},
"linked_schemas": []
}
  • Replace blt9f8e7d6c5b4a3210 with the UID of an entry in your stack, and PostCard with a component you registered.
  • Every contentstack and contentstack_queries binding has a matching item in data_sources. The API doesn't check this, and a binding with no item shows the prop's default.
  • The pinned data belongs to the Section. Every Template that places it shows the same author and the same query, and the Template's own data_sources doesn't list them.

Which composition reads which pinned data​

CompositionIts pinned entries and queries
Connected TemplateIts own data_sources
Freeform TemplateIts own data_sources
SectionIts own data_sources. They apply wherever the Section is placed.

For every value source and composition kind, see Which sources each kind of composition has.

Report a problem with this page