--- title: TypeScript quickstart | Lightfield description: Get started with the Lightfield API using TypeScript. --- The Lightfield API is currently in beta. Methods, parameters, and response schemas may change as we incorporate feedback during this period. This guide walks you through making your first request to the Lightfield API using the official TypeScript SDK. ## Installation Install the library from [npm](https://www.npmjs.com/package/lightfield): Terminal window ``` npm install lightfield ``` ## Get an API key An [API key](/using-the-api/api-keys/index.md) can be created in [Lightfield settings](https://crm.lightfield.app/crm/settings/api-keys) (admin only). When creating the key, select the [scopes](/using-the-api/scopes/index.md) your integration needs. For the example below, you’ll need `accounts:read`. ## Make your first request Create a client and [list](/api/resources/account/methods/list/index.md) one account to verify your key and scope. **1. Create a new file** (e.g. `quickstart.ts`) and paste in: ``` import Lightfield from "lightfield"; const client = new Lightfield({ apiKey: "My API Key", }); async function main() { const accounts = await client.account.list({ limit: 1 }); console.log(accounts); } main(); ``` **2. Replace `"My API Key"`** with your actual API key (`sk_lf_...`). **3. Run the script** from your terminal (from the same directory as the file): Terminal window ``` npx tsx quickstart.ts ``` A successful response looks like: ``` { "data": [ { "id": "id", "createdAt": "createdAt", "fields": { "foo": { "value": "string", "valueType": "valueType" } }, "httpLink": "httpLink", "relationships": { "foo": { "cardinality": "cardinality", "objectType": "objectType", "values": [ "string" ] } } } ], "object": "list", "totalCount": 1 } ``` With `limit: 1` you get at most one account. To fetch more results, use `limit` and `offset` — see [List methods](/using-the-api/list-endpoints/index.md) for pagination. The full API is in the [TypeScript API Reference](/api/typescript/index.md). **Error handling:** The SDK raises typed exceptions you can catch. If your API key is wrong you’ll get a `Lightfield.AuthenticationError`: ``` import Lightfield from "lightfield"; const client = new Lightfield({ apiKey: "invalid-key" }); async function main() { try { await client.account.list({ limit: 1 }); } catch (err) { if (err instanceof Lightfield.AuthenticationError) { console.log(err.status); // 401 console.log(err.message); } } } main(); ``` If the key is valid but missing the required scope, a `Lightfield.PermissionDeniedError` (403) is thrown instead. For more on error responses and how to handle them, see [Errors](/using-the-api/errors/index.md). ## Next steps - **[Objects in Lightfield](/objects-in-lightfield/object-types/index.md)** — Overview of object types (accounts, contacts, opportunities, and more) and how they relate. - **[TypeScript API Reference](/api/typescript/index.md)** — Full API reference with TypeScript code examples. - **[Rate limits](/using-the-api/rate-limits/index.md)** — Request limits and how to handle 429 responses. - **[Idempotency](/using-the-api/idempotency/index.md)** — Safe retries for create and update operations.