Skip to main content

Nested Children

RestAPI.com enables efficient management of hierarchical data structures. Update parent and child collections within a single transaction with automatic rollback support.

How It Works

When updating nested data, three simple rules apply:

ScenarioAction
Items with an IDUpdated
Items without an IDInserted as new
Items omitted from requestDeleted

All operations occur within the same transaction, ensuring data integrity.

Syntax

Nested collections use the pattern:

childCollection.fieldPointingToParent

For example, tasks.project refers to the tasks collection where project is the lookup field pointing to the parent.

note

Nested children are limited to one level of depth. You cannot nest children within children in a single request.

Example

Update a project with its tasks in a single request:

PATCH https://eu.restapi.com/my-api/projects/abc-123
Content-Type: application/json

{
"name": "Website Redesign",
"tasks.project": [
{ "id": "task-1", "title": "Design mockups", "status": "done" },
{ "id": "task-2", "title": "Implement frontend", "status": "in-progress" },
{ "title": "Write tests" }
]
}

In this example:

  • task-1 and task-2 are updated (they have IDs)
  • A new task "Write tests" is created (no ID)
  • Any other tasks linked to this project are deleted (not in the array)

Benefits

Atomic Operations

All changes succeed or fail together. No partial updates that leave your data inconsistent.

Security Policy Compliance

Works seamlessly with Security Policy Rules. Create parent and child records in the same transaction without creating dangling entities.

Simplified Client Code

No need for multiple API calls to manage related data. One request handles the entire hierarchy.

Use Cases

  • Projects with tasks — Update project details and task list together
  • Orders with line items — Modify order and items atomically
  • Categories with products — Reorganize category contents in one call
  • Documents with comments — Manage document and feedback together