---
title: "Insert records into a table"
method: POST
path: "/api/db/{project_id}/rest/v1/{table}"
tags: ["Database"]
---

# Insert records into a table

`POST /api/db/{project_id}/rest/v1/{table}`

## Request

- Base URL: `https://core.blink.new`
- URL: `https://core.blink.new/api/db/{project_id}/rest/v1/{table}`
- Auth: one of:
  - HTTP bearer
  - none

Insert one record (JSON object) or multiple records (JSON array) into a table.

**Authentication**
- Requires a valid bearer token unless the project policy has `require_auth: false`.
- Service-role tokens bypass row-level security.

**Row-Level Security (RLS)**
For non-service tokens with `owner` mode RLS, the `user_id` column (or configured
owner field) is automatically set to the caller's user ID. Any client-supplied
value for that field is ignored and overwritten.

**Upsert / conflict handling**
Append `?on_conflict=col1,col2` to perform an upsert on the specified columns.
Non-conflict columns are updated; conflict columns are unchanged.

**Return inserted rows**
Send the `Prefer: return=representation` header to receive the inserted rows
in the response body (uses `RETURNING *`). Response is `201` either way.

camelCase keys in the request body are automatically converted to snake_case.

## Path parameters

- `project_id` string, required
- `table` string, required

## Query parameters

- `on_conflict` 'return=representation' | 'return=minimal'

## Request body

- union
  - TableRecord: Generic table record with dynamic fields
  - TableRecord[]: Multiple records to insert

## Response `201`

Record(s) inserted successfully

- union
  - object: Empty object when Prefer header is not set
  - TableRecord[]: Inserted rows when Prefer: return=representation is set

## Other responses

- `400`: Validation error
- `401`: Unauthenticated and require_auth is enabled
- `403`: Write access denied by table policy, or RLS owner column missing
- `404`: No database found for the given project_id
- `409`: Unique or primary-key constraint violation (duplicate). Branch on HTTP 409; body carries code "23505".
- `500`: Internal server error

---

[API](https://skmtc.dev/blink/apis/blink-apis.md) - [All operations](https://skmtc.dev/blink/apis/blink-apis/llms.txt) - [OpenAPI document](https://skmtc.dev/blink/apis/blink-apis/revisions/4c59c706078e?raw)
