Client Usage
JavaScript SDK
Install and use the official Amarsia JavaScript and TypeScript SDK.
Installation
npm install @amarsia/sdkThe SDK ships with full TypeScript types — no additional @types package needed.
Quick start
import { Amarsia } from '@amarsia/sdk';
const client = new Amarsia({
apiKey: process.env.AMARSIA_API_KEY,
});
// List resources
const resources = await client.resources.list();
// Create a resource
const contact = await client.resources.create({
type: 'contact',
fields: {
email: 'jane@example.com',
name: 'Jane Doe',
},
});
console.log(contact.id); // res_01j...Authentication
Pass your API key when instantiating the client. The SDK reads from process.env.AMARSIA_API_KEY automatically if no key is provided:
// Explicit key
const client = new Amarsia({ apiKey: 'sk_live_...' });
// Uses AMARSIA_API_KEY env var automatically
const client = new Amarsia();Never hardcode API keys in source code. Use environment variables.
Core operations
Resources
// List
const { data, meta } = await client.resources.list({ type: 'contact', limit: 20 });
// Get by ID
const resource = await client.resources.get('res_01j...');
// Create
const newResource = await client.resources.create({ type: 'contact', fields: { ... } });
// Update
const updated = await client.resources.update('res_01j...', { fields: { name: 'Updated Name' } });
// Delete
await client.resources.delete('res_01j...');Events
// List events for a resource
const events = await client.events.list({ resourceId: 'res_01j...' });
// Get a specific event
const event = await client.events.get('evt_01j...');Pagination
All list methods return a cursor-paginated response:
let cursor: string | undefined;
do {
const { data, meta } = await client.resources.list({ limit: 100, cursor });
// process data...
cursor = meta.nextCursor;
} while (cursor);TypeScript
The SDK exports all resource and event types:
import type { Resource, Event, CreateResourceParams } from '@amarsia/sdk';
async function createContact(params: CreateResourceParams): Promise<Resource> {
return client.resources.create(params);
}