SDK Reference
Complete reference for the SheetsAPI JavaScript/TypeScript SDK - installation, client config, all methods, types, and error handling.
The SheetsAPI JavaScript SDK is a typed wrapper around the REST API. It handles authentication, pagination, and error normalisation so your application code stays clean.
Installation
npm install @gkit/sheets-sdk
# or
pnpm add @gkit/sheets-sdk
# or
bun add @gkit/sheets-sdkInitialisation
import { SheetsClient } from "@gkit/sheets-sdk";
const client = new SheetsClient({
userKey: process.env.SHEETS_USER_KEY!,
apiKey: process.env.SHEETS_API_KEY!,
// Optional:
baseUrl: "https://sheetsapi.gkit.mreshank.com", // default
timeout: 10_000, // ms, default 30 000
retries: 3, // on 5xx or network error
});Methods
client.get(sheet, params?)
Fetch a page of rows.
const { data, meta } = await client.get<Product>("Products", {
limit: 20,
offset: 0,
sort: "-price",
search: "category:books",
fields: ["id", "name", "price"],
});Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
limit | number | 100 | Rows per page (max 500) |
offset | number | 0 | Rows to skip |
sort | string | - | Column name, prefix with - for descending |
search | string | - | field:value filter |
fields | string[] | - | Only return these columns |
Returns: Promise<SheetResponse<T>>
client.getAll(sheet, params?)
Fetch all rows by paginating automatically.
const products = await client.getAll<Product>("Products", {
sort: "name",
search: "category:books",
});
// Returns T[] - all matching rowsInternally makes as many requests as needed with limit=500.
Parameters: Same as get(), except limit and offset are ignored.
Returns: Promise<T[]>
client.post(sheet, row)
Append one row to the sheet.
const created = await client.post<Product>("Products", {
id: crypto.randomUUID(),
name: "Widget Pro",
price: "49.99",
category: "Widgets",
});
// Returns the appended rowParameters:
| Name | Type | Description |
|---|---|---|
sheet | string | Sheet name |
row | Record<string, string> | Column key/value pairs |
Returns: Promise<T>
client.find(sheet, field, value, params?)
Find rows matching a specific field value. Convenience wrapper around get() with
a search=field:value parameter.
const [product] = await client.find<Product>("Products", "id", productId);
if (!product) throw new Error("Not found");Returns: Promise<T[]>
Types
interface SheetResponse<T> {
data: T[];
meta: {
total: number;
limit: number;
offset: number;
};
}
interface SheetsClientConfig {
userKey: string;
apiKey: string;
baseUrl?: string; // default: "https://sheetsapi.gkit.mreshank.com"
timeout?: number; // ms, default 30 000
retries?: number; // default 3
}Error handling
The SDK throws SheetsApiError for all non-2xx responses:
import { SheetsApiError } from "@gkit/sheets-sdk";
try {
const { data } = await client.get("Products");
} catch (err) {
if (err instanceof SheetsApiError) {
console.error(err.status); // HTTP status code
console.error(err.message); // Error message from the API
console.error(err.sheet); // Which sheet caused the error
}
}SheetsApiError properties:
| Property | Type | Description |
|---|---|---|
status | number | HTTP status (400, 401, 403, 404, 429, 500) |
message | string | Human-readable error |
sheet | string | Sheet name from the request |
retryAfter | number | null | Seconds to wait (from Retry-After header) |
Pagination helper
async function* paginate<T>(
client: SheetsClient,
sheet: string,
params: Record<string, string | number> = {},
): AsyncGenerator<T[]> {
const pageSize = 100;
let offset = 0;
let total = Infinity;
while (offset < total) {
const { data, meta } = await client.get<T>(sheet, {
...params,
limit: pageSize,
offset,
});
total = meta.total;
offset += pageSize;
yield data;
}
}
// Usage:
for await (const page of paginate(client, "Products")) {
processPage(page);
}REST API quick reference
If you prefer to call the API directly (without the SDK):
Base URL
https://sheetsapi.gkit.mreshank.com
Endpoints
| Method | Path | Description |
|---|---|---|
GET | /api/spreadsheets/{userKey}/{sheet} | List rows |
POST | /api/spreadsheets/{userKey}/{sheet} | Append a row |
GET | /api/me | Verify key and return account info |
Query parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | integer | 100 | Rows per page, max 500 |
offset | integer | 0 | Rows to skip |
sort | string | - | Column name, - prefix = descending |
search | string | - | field:value filter |
fields | string | - | Comma-separated column names |
Rate limits
| Tier | Requests/minute | Requests/day |
|---|---|---|
| Free | 60 | 1 000 |
| Pro | 300 | 10 000 |
| Team | 1 000 | 100 000 |
See Rate Limits for full details and retry guidance.