TypeScript quickstart
Get started with the Lightfield API using TypeScript.
This guide walks you through making your first request to the Lightfield API using the official TypeScript SDK.
Installation
Section titled “Installation”Install the library from npm:
npm install lightfieldGet an API key
Section titled “Get an API key”An API key can be created in Lightfield settings (admin only).
When creating the key, select the scopes your integration needs.
For the example below, you’ll need accounts:read.
Make your first request
Section titled “Make your first request”Create a client and list 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):
npx tsx quickstart.tsA 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 for pagination. The full API is in the TypeScript API Reference.
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.
Next steps
Section titled “Next steps”- Objects in Lightfield — Overview of object types (accounts, contacts, opportunities, and more) and how they relate.
- TypeScript API Reference — Full API reference with TypeScript code examples.
- Rate limits — Request limits and how to handle 429 responses.
- Idempotency — Safe retries for create and update operations.