> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.labric.co/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.labric.co/_mcp/server.

# Write

POST https://platform.labric.co/api/v1/tools/write
Content-Type: application/json

Write records to a table.

Inserts or updates records in the specified target table. Supports batch
inserts, upserts with match columns, default value functions (DATETIME_NOW,
UUID4), and optional dry-run validation. A job execution is created
automatically if one is not provided.

Reference: https://docs.labric.co/api-reference/labric-api/tools/write

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: openapi-tools
  version: 1.0.0
paths:
  /api/v1/tools/write:
    post:
      operationId: write
      summary: Write
      description: >-
        Write records to a table.


        Inserts or updates records in the specified target table. Supports batch

        inserts, upserts with match columns, default value functions
        (DATETIME_NOW,

        UUID4), and optional dry-run validation. A job execution is created

        automatically if one is not provided.
      tags:
        - tools
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  additionalProperties:
                    description: Any type
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '422':
          description: Unprocessable Content
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorSchema'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LabricWriteSchema'
servers:
  - url: https://platform.labric.co
    description: https://platform.labric.co
components:
  schemas:
    LabricWriteSchemaTargetType:
      type: string
      enum:
        - table
        - core-table
      description: The type of target. Currently 'table' or 'core-table'.
      title: LabricWriteSchemaTargetType
    LabricWriteSchema:
      type: object
      properties:
        target_name:
          type: string
          description: The name of the table to write to.
        target_type:
          $ref: '#/components/schemas/LabricWriteSchemaTargetType'
          description: The type of target. Currently 'table' or 'core-table'.
        data:
          type: array
          items:
            type: object
            additionalProperties:
              description: Any type
          description: List of record dicts to write.
        batch_insert_ok:
          type: boolean
          default: false
          description: If True, allow batch insert of multiple records.
        params_to_match_for_update:
          type:
            - array
            - 'null'
          items:
            type: string
          description: Column names to match on when updating existing records.
        defaults:
          type:
            - object
            - 'null'
          additionalProperties:
            type: string
          description: >-
            Map of field names to default function names (e.g. 'DATETIME_NOW',
            'UUID4').
        mode:
          type: string
          description: Write mode (e.g. 'create', 'create-or-update').
        job_execution_id:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            Existing job execution ID to associate with this write. If omitted,
            a new one is created.
        job_name:
          type:
            - string
            - 'null'
          description: >-
            Name for the auto-created job. Defaults to 'Off-Platform Manual
            Job'.
        collect_output:
          type: boolean
          default: false
          description: If True, return the written records in the response.
        dry_run:
          type: boolean
          default: false
          description: >-
            If True, resolve references, check table and column validity, and
            return the execution plan without committing changes.
      required:
        - target_name
        - target_type
        - data
        - mode
      description: Write records to a target table or core-table.
      title: LabricWriteSchema
    ErrorSchema:
      type: object
      properties:
        detail:
          type: string
      required:
        - detail
      title: ErrorSchema
    ValidationErrorSchema:
      type: object
      properties:
        detail:
          type: array
          items:
            type: object
            additionalProperties:
              description: Any type
      required:
        - detail
      description: Shape of Ninja's built-in 422 request-validation error response.
      title: ValidationErrorSchema
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer

```

## Examples



**Request**

```json
{
  "target_name": "customer_orders",
  "target_type": "table",
  "data": [
    {}
  ],
  "mode": "create-or-update"
}
```

**Response**

```json
[
  {}
]
```

**SDK Code**

```python
import requests

url = "https://platform.labric.co/api/v1/tools/write"

payload = {
    "target_name": "customer_orders",
    "target_type": "table",
    "data": [{}],
    "mode": "create-or-update"
}
headers = {
    "Authorization": "Bearer <api_key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://platform.labric.co/api/v1/tools/write';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <api_key>', 'Content-Type': 'application/json'},
  body: '{"target_name":"customer_orders","target_type":"table","data":[{}],"mode":"create-or-update"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://platform.labric.co/api/v1/tools/write"

	payload := strings.NewReader("{\n  \"target_name\": \"customer_orders\",\n  \"target_type\": \"table\",\n  \"data\": [\n    {}\n  ],\n  \"mode\": \"create-or-update\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <api_key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://platform.labric.co/api/v1/tools/write")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <api_key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"target_name\": \"customer_orders\",\n  \"target_type\": \"table\",\n  \"data\": [\n    {}\n  ],\n  \"mode\": \"create-or-update\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://platform.labric.co/api/v1/tools/write")
  .header("Authorization", "Bearer <api_key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"target_name\": \"customer_orders\",\n  \"target_type\": \"table\",\n  \"data\": [\n    {}\n  ],\n  \"mode\": \"create-or-update\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://platform.labric.co/api/v1/tools/write', [
  'body' => '{
  "target_name": "customer_orders",
  "target_type": "table",
  "data": [
    {}
  ],
  "mode": "create-or-update"
}',
  'headers' => [
    'Authorization' => 'Bearer <api_key>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://platform.labric.co/api/v1/tools/write");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <api_key>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"target_name\": \"customer_orders\",\n  \"target_type\": \"table\",\n  \"data\": [\n    {}\n  ],\n  \"mode\": \"create-or-update\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <api_key>",
  "Content-Type": "application/json"
]
let parameters = [
  "target_name": "customer_orders",
  "target_type": "table",
  "data": [[]],
  "mode": "create-or-update"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://platform.labric.co/api/v1/tools/write")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```