API Methods
The SDK provides methods for all Space Invoices API endpoints, organized by resource.
Invoices
| Method | Description |
|---|---|
invoices.list(params?) | List invoices with filtering and pagination |
invoices.get({ id }) | Get invoice by ID |
invoices.create({ entityId, body }) | Create new invoice |
invoices.update({ id, body }) | Update invoice |
invoices.delete({ id }) | Delete invoice |
invoices.renderPdf({ id }) | Render invoice as PDF |
invoices.send({ id, body }) | Send invoice via email |
// List invoices
const _invoices = await sdk.invoices.list({
entityId: "ent_123",
limit: 20,
});
// Get single invoice
const _invoice = await sdk.invoices.get({ id: "inv_123" });
// Create invoice
const _newInvoice = await sdk.invoices.create({
entityId: "ent_123",
body: {
date: "2024-01-15",
items: [{ name: "Service", price: 100 }],
},
});
// Update invoice
await sdk.invoices.update({
id: "inv_123",
body: { dueDate: "2024-02-15" },
});
// Delete invoice
await sdk.invoices.delete({ id: "inv_123" });Customers
| Method | Description |
|---|---|
customers.list(params?) | List customers |
customers.get({ id }) | Get customer by ID |
customers.create({ entityId, body }) | Create customer |
customers.update({ id, body }) | Update customer |
customers.delete({ id }) | Delete customer |
// List customers
const _customers = await sdk.customers.list({
entityId: "ent_123",
});
// Get customer
const _customer = await sdk.customers.get({ id: "cust_123" });
// Create customer
const _newCustomer = await sdk.customers.create({
entityId: "ent_123",
body: {
name: "Acme Corp",
email: "billing@acme.com",
address: "123 Business St",
city: "New York",
country: "US",
},
});
// Update customer
await sdk.customers.update({
id: "cust_123",
body: { email: "new-email@acme.com" },
});Items
| Method | Description |
|---|---|
items.list(params?) | List items/products |
items.get({ id }) | Get item by ID |
items.create({ entityId, body }) | Create item |
items.update({ id, body }) | Update item |
items.delete({ id }) | Delete item |
// List items
const _items = await sdk.items.list({
entityId: "ent_123",
});
// Create item
const _item = await sdk.items.create({
entityId: "ent_123",
body: {
name: "Consulting Hour",
unit: "hour",
price: 150,
taxIds: ["tax_123"],
},
});
// Update item
await sdk.items.update({
id: "item_123",
body: { price: 175 },
});Payments
| Method | Description |
|---|---|
payments.list(params?) | List payments |
payments.get({ id }) | Get payment by ID |
payments.create({ documentId, body }) | Record payment |
payments.delete({ id }) | Delete payment |
// List payments for a document
const _payments = await sdk.payments.list({
documentId: "inv_123",
});
// Record a payment
const _payment = await sdk.payments.create({
documentId: "inv_123",
body: {
amount: 500,
date: "2024-01-20",
method: "bank_transfer",
},
});
// Delete payment
await sdk.payments.delete({ id: "pay_123" });Entities
| Method | Description |
|---|---|
entities.list(params?) | List entities |
entities.get({ id }) | Get entity by ID |
entities.create({ body }) | Create entity |
entities.update({ id, body }) | Update entity |
// List entities
const _entities = await sdk.entities.list();
// Get entity
const _entity = await sdk.entities.get({ id: "ent_123" });
// Create entity (for multi-tenant platforms)
const _newEntity = await sdk.entities.create({
body: {
name: "New Business",
email: "contact@business.com",
country: "US",
},
});
// Update entity
await sdk.entities.update({
id: "ent_123",
body: { name: "Updated Business Name" },
});Taxes
| Method | Description |
|---|---|
taxes.list(params?) | List tax rates |
taxes.get({ id }) | Get tax by ID |
taxes.create({ entityId, body }) | Create tax rate |
taxes.update({ id, body }) | Update tax rate |
taxes.delete({ id }) | Delete tax rate |
Other Documents
The SDK also supports:
estimates— Quotes and estimatescreditNotes— Credit notesadvanceInvoices— Advance invoicesrecurringInvoices— Recurring invoices
All follow the same pattern as invoices.
Pagination
All list methods support cursor-based pagination:
// First page
const page1 = await sdk.invoices.list({
entityId: "ent_123",
limit: 20,
});
// Next page using cursor
if (page1.cursor) {
const _page2 = await sdk.invoices.list({
entityId: "ent_123",
limit: 20,
cursor: page1.cursor,
});
}Filtering
Filter results using query parameters:
// Filter by date range
const _invoices = await sdk.invoices.list({
entityId: "ent_123",
dateFrom: "2024-01-01",
dateTo: "2024-01-31",
});
// Filter by status
const _unpaid = await sdk.invoices.list({
entityId: "ent_123",
status: "unpaid",
});
// Filter customers by search
const _customers = await sdk.customers.list({
entityId: "ent_123",
search: "acme",
});Error Handling
The SDK throws errors for failed requests:
try {
const _invoice = await sdk.invoices.get("invalid_id");
} catch(error) {
if (error.status === 404) {
} else if (error.status === 401) {
} else {
}
}Next Steps
- Zod Schemas — Form validation with Zod
- API Reference — Full API documentation