Guide 06 · Developer docs

The APIs: REST, GraphQL and custom endpoints

Every Core dna site answers three kinds of API request under /cdna-api: REST for everything, GraphQL for reads that span several entity types, and web events for endpoints you define yourself as jobs. Which fits which task, one worked request for each, and what is true of all three. Jobs were called hooks until the module was renamed Orchestration; the API's routes still use the old name.

L1–L3
Unit 02 · Writing content

Editing component collections

A component collection is a list of components in one layout area: the sections of a page, the blocks of a guide page. Which key changes it, how positions count, why a position can point at the wrong element after a removal, and how to place a global component.

Who this is for. The integrations engineer adding, moving or removing sections across many records. Every key on this page goes inside patchRevision, beside originRevision and activeRevision (Choosing a write). The Collection operations reference has a real request and response for each.

Which key

ToSend
Replace the whole collection"areaContent(area)": [ …components ]
Replace one element with a new component"areaCollectionElement(area, n)": { …component } (example)
Change some areas of one element"patchAreaCollectionElement(area, n)": {"areaContent(name)": …} (example)
Insert an element so it becomes element n"insertAreaCollectionElement(area, n)": { …component } (example)
Add one at the end"appendAreaCollectionElement(area)": { …component } (example)
Add several at the end"appendAreaCollectionElements(area)": [ …components ] (example)
Remove an element"removeAreaCollectionElement(area, n)": true (example)

A component is {"name": …, "layout": <component layout id>, "areas": {…}}, its layout areas in the write shape. In a list, an element can carry "published": false to be saved hidden. Use the key names above exactly: areaCollectionElement(area, n) is the one for a replace, not setAreaCollectionElement(area, n), which some clients send instead.

How positions count

  • Positions start at 1.
  • Within one request, every position refers to the collection as it was before the request. Removing 2 and 3 in one request removes the second and third elements, in whichever order the keys are written. Several operations, and other changes to the revision, can go in one request (example).
  • Positions are not shown when you read. An element in areasContent has a componentId, a name, a layout and its layout areas, but no position and no published flag.
  • componentId is not an address. Every new revision copies the components and gives them new ids. On the sandbox page, a section read as componentId 17985 came back as 20771 after one unrelated patch.

Keeping positions correct after a removal

A removal does not renumber the elements after it. Each element keeps the position it was stored with, so a later request's position n addresses the element stored at n, not the n-th one. Measured on this site's sandbox page, one request at a time, each answering 200:

RequestBeforeAfter
removeAreaCollectionElement(pageSections, 2)A · B · C · DA · C · D, stored at 1, 3, 4
insertAreaCollectionElement(pageSections, 3), with the position taken from a fresh readA · C · DA · C · X · D: right

Inserts and appends land where you expect. Take every position from a fresh read taken after the last change, since the stored order is not renumbered for you, and the drift carries into every later revision.

Three rules keep a client safe:

  1. Make every change to one collection in one request, with positions taken from a fresh read. Within the request, positions refer to the collection before it, so they are right.
  2. After a removal, rewrite the collection before any later positional edit. Sending the whole list with areaContent(area) stores the elements at 1, 2, 3 again. Map the read to the write shape first (Writing areas), or the rewrite loses content.
  3. Check the result. Read the collection after a positional edit and compare the element names you expected with the ones you got; roll back with activeRevision if they differ (Going live).

On a collection you did not create, assume a removal has happened at some point.

Global components

A global component is one component shown on many records; editing it changes every one of them. To place it in a collection, refer to it by id with "global": true, and send nothing else:

Append a global component to a page's sections
PUT /cdna-api/pages/page/1885?properties={id,activeRevision{id}} HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json

{
  "patchRevision": {
    "originRevision": 3277,
    "activeRevision": true,
    "appendAreaCollectionElement(pageSections)": {
      "global": true,
      "id": 5
    }
  }
}
Response 200 OK
{
  "result": "success",
  "data": {
    "id": 1885,
    "activeRevision": {
      "id": 3446
    }
  },
  "message": "The Page has been saved successfully."
}
Real response from this documentation site, on its API sandbox page

Read back, the new element has the global component's own id, componentGlobal: true and no areas: its content lives on the global component.

JSON The last element of activeRevision{areasContent}
{"componentId": 5, "componentName": "Need help callout", "componentLayout": 37, "componentGlobal": true}
  • Do not send areas with a global reference. The platform passes them to the global component as a new revision of it, not to the record you are editing.
  • To copy a collection that holds a global component, write the reference, {"global": true, "id": …}, not a copy of its layout areas; a copy stops following the global component's edits.
  • To change the global component itself, use the global components routes in the API reference, knowing it changes every record that shows it.
Go deeper

Was this page helpful?

Your answer goes to the docs team.