POST
Insert a new record into a table using the Datasquirel REST API or npm package.Overview
Use the POST endpoint to insert a new record into a table. Provide the data as a plain object — the keys must match your table's field names.
npm Package
import datasquirel from "@moduletrace/datasquirel"; const result = await datasquirel.crud.insert({ dbName: "my_database", tableName: "users", body: { name: "Alice", email: "[email protected]", is_active: 1, }, apiKey: process.env.DATASQUIREL_API_KEY, }); // result.payload is the inserted record's ID console.log(result.payload);
Insert Multiple Records (Batch)
You can insert multiple records in a single request by passing an array in a batchData field:
const result = await datasquirel.crud.insert({ dbName: "my_database", tableName: "tags", body: { batchData: [ { name: "javascript" }, { name: "typescript" }, { name: "sql" }, ]}, apiKey: process.env.DATASQUIREL_API_KEY, });
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
dbName | string | Yes | The database slug |
tableName | string | Yes | The table to insert into |
body | object | Yes | The record to insert. Keys must match field names |
apiKey | string | No | API key. Falls back to DATASQUIREL_API_KEY environment variable |
REST API
POST /api/v1/crud/{dbName}/{tableName}
Headers:
Authorization: Bearer YOUR_API_KEY Content-Type: application/json
Body:
{ "name": "Alice", "email": "[email protected]", "is_active": 1 }
Response
{ "success": true, "payload": 7 }
A successful response returns success: true and payload containing the insertId (the auto-incremented id of the new record).