Bind section to collection
bind_section_to_collectionConnect a Uislice section on a page to a collection (datasource), so the section's items render entries from that collection instead of static placeholder content.
This mirrors the "Datasource" panel in the Apollo editor. It is a separate operation from save_section_content / save_page_content / save_partial_content; those tools do NOT change a section's collection binding. Use it after inserting a list-style section (cards, grid, listing) that should show collection entries.
A binding has two parts: the collection, and a mapping that says which entry fields fill which item fields. Pass the mapping as connection, keyed by the section's list path, for example {"ctx.items": {"dataSourcePath": "entries", "fields": {"title.value": "<%=entryName%>", "desc.value": "<%=summary%>", "media[0].src": "<%=image.src%>"}}}: entryName is the entry's name and the other names are the collection's fields (get_collection lists them). Without connection, a section that already has a mapping keeps it; otherwise a mapping is built from the section's items and the collection's fields (the entry name as the item title, a text field as the description), and the result says what it mapped. When no mapping can be built the result carries a warning and the section keeps showing its own items until one is sent.
Mechanics: looks up the section by sectionId (id or logicalId), validates that section.type === "Uislice", and applies one SET_COLLECTION operation with the mapping: both land on the page's draft under the revision lock, checked against the section's current anchor, and the draft is forked from the published head first when needed.
Errors: returns a clear error if the section is not found, the section is a Partial (binding partials is not supported here), the collection does not exist, or the section changed while the request was in flight (BASE_VERSION_MISMATCH: read the page again and retry with a new idempotencyKey).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | The page ID containing the section | |
| projectId | Yes | The project ID | |
| sectionId | Yes | The section's id or logicalId (from get_page_content) | |
| connection | No | The mapping, keyed by the section path it fills, e.g. {"ctx.items": {"dataSourcePath": "entries", "fields": {"title.value": "<%=entryName%>"}}}. Omit to keep the section's mapping or have one built. | |
| collectionId | Yes | The collection ID to connect | |
| idempotencyKey | No | Stable key for a safe retry: the same key replays the first result instead of applying twice. Reuse a key only for a call that got no answer; after any error, read the page again and use a new key. |