Skip to content
Get started

Batch Write

post/api/v1/tools/batch-write

Write records to multiple tables in a single transaction.

Supports:

  • Batch references: Use "_ref" to label records, "@refname" to reference them
  • Natural keys: Use human-readable values for foreign keys (e.g., recipe name)
  • Automatic FK ordering: Tables are inserted in dependency order
  • Upsert mode: Update existing records based on match columns
  • Dry run: Validate without committing changes
Body ParametersExpand Collapse
tables: map[array of map[unknown]]

Map of table_name to list of records to insert.

options: optional object { dry_run, match_on, mode, return_records }

Options for controlling batch write behavior.

dry_run: optional boolean

If True, validate without committing changes.

match_on: optional map[array of string]

For upsert: which columns to match on, per table. Example: {"production_run": ["run_code"]}

mode: optional "insert" or "upsert"

'insert' creates new records, and fails if the record already exists. 'upsert' creates or updates based on match_on columns.

Accepts one of the following:
"insert"
"upsert"
return_records: optional boolean

If True, include created/updated records in response.

ReturnsExpand Collapse
refs: map[string]

Map of _ref labels to their created IDs.

summary: map[object { created, updated } ]

Count of created/updated records per table.

created: optional number

Number of records created.

updated: optional number

Number of records updated.

plan: optional object { insert_order, operations }

Execution plan returned by dry_run.

insert_order: array of string

Order in which tables will be inserted.

operations: array of map[unknown]

Operations that would be performed.

records: optional map[array of map[unknown]]

Created/updated records (only if return_records=True).

success: optional boolean

Whether the operation succeeded.

Batch Write
curl https://platform.labric.co//api/v1/tools/batch-write \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $LABRIC_API_KEY" \
    -d '{
          "tables": {
            "foo": [
              {
                "foo": "bar"
              }
            ]
          }
        }'
{
  "refs": {
    "foo": "string"
  },
  "summary": {
    "foo": {
      "created": 0,
      "updated": 0
    }
  },
  "plan": {
    "insert_order": [
      "string"
    ],
    "operations": [
      {
        "foo": "bar"
      }
    ]
  },
  "records": {
    "foo": [
      {
        "foo": "bar"
      }
    ]
  },
  "success": true
}
Returns Examples
{
  "refs": {
    "foo": "string"
  },
  "summary": {
    "foo": {
      "created": 0,
      "updated": 0
    }
  },
  "plan": {
    "insert_order": [
      "string"
    ],
    "operations": [
      {
        "foo": "bar"
      }
    ]
  },
  "records": {
    "foo": [
      {
        "foo": "bar"
      }
    ]
  },
  "success": true
}