# Writing rows

Source: https://cubibase.com/docs/data-api/writing

Also available: [Markdown version](https://cubibase.com/docs/data-api/writing.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

POST inserts one row, PATCH updates one row by primary key, DELETE removes it. Each returns the affected row with every column.

## Insert a row

`POST /rest/v1/{table}` with a JSON object of column values. Columns with defaults can be omitted. The response is `201` with the full inserted row.

**Insert · request**

```http
POST https://example-project.api.cubibase.com/rest/v1/customers
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <USER_JWT>
Content-Type: application/json

{
  "name": "Mina Cho",
  "email": "mina@example.com",
  "plan": "pro",
  "owner_id": "<USER_ID>"
}
```

> **important**: On a table with a user column, set that column to the calling user’s id (the JWT `sub`). Writing another user’s id fails the policy’s `WITH CHECK` with `403 forbidden`.

## Update a row

`PATCH /rest/v1/{table}/{id}` with the fields to change. Only the listed columns are touched; the response is the full updated row.

**Update · request**

```http
PATCH https://example-project.api.cubibase.com/rest/v1/customers/8c1a0b2e-7d44-4a11-9c31-0b51a6e4d901
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <USER_JWT>
Content-Type: application/json

{
  "plan": "team"
}
```

## Delete a row

`DELETE /rest/v1/{table}/{id}` removes the row and returns it in `data`. A row that does not exist — or is hidden by the user’s policy — returns `404 not_found`.

**Delete · request**

```http
DELETE https://example-project.api.cubibase.com/rest/v1/customers/8c1a0b2e-7d44-4a11-9c31-0b51a6e4d901
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <USER_JWT>
```

## Constraint errors

PostgreSQL constraints surface as stable error codes, so your app can react without parsing messages:

| Status | Code | Cause |
| --- | --- | --- |
| `409` | `conflict` | Unique constraint violated (e.g. duplicate email) |
| `400` | `not_null_violation` | A required column was omitted |
| `409` | `foreign_key_violation` | A referenced row does not exist |
| `400` | `check_violation` | A value failed a check constraint |
| `400` | `invalid_input` | A value does not fit the column type |
| `403` | `forbidden` | The row policy rejected the write |

> **note**: Bodies are limited to 64 fields, and row ids to 200 characters. `PATCH` and `DELETE` require a table with a single primary key column.

## Additional resources

- [Querying rows](https://cubibase.com/docs/data-api/querying) Read back what you wrote.
- [Error codes](https://cubibase.com/docs/reference/errors) Every code the engine can return.
