@kanvas/core SDK
The official JavaScript/TypeScript SDK for Kanvas. Wraps the GraphQL API with typed methods for every module.
Installation
npm install @kanvas/coreSetup with Super Admin Key
For agents and server-to-server — no login required:
import KanvasCore from "@kanvas/core";
const kanvas = new KanvasCore({
url: process.env.KANVAS_API_URL,
key: process.env.KANVAS_ADMIN_KEY, // X-Kanvas-Key (super admin)
});Setup with App Key + User Auth
For frontend apps with user sessions:
import KanvasCore, { genericAuthMiddleware } from "@kanvas/core";
const kanvas = new KanvasCore({
url: process.env.KANVAS_API_URL,
key: process.env.KANVAS_APP_KEY, // X-Kanvas-App (app key)
middlewares: [
genericAuthMiddleware(() => {
return localStorage.getItem("kanvas_token") || "";
}),
],
});Available Modules
| Field | Type | Description |
|---|---|---|
| kanvas.auth | Auth | Login, logout, register, refresh token, password reset |
| kanvas.users | Users | User management, invites, device linking |
| kanvas.leads | Leads | Create, update, delete, fetch leads |
| kanvas.people | People | Contact management |
| kanvas.companies | Companies | Company data |
| kanvas.companiesBranches | Branches | Branch management |
| kanvas.inventory | Inventory | Products, variants, warehouses, categories, attributes |
| kanvas.order | Order | Order creation, payment intents |
| kanvas.cart | Cart | Shopping cart operations |
| kanvas.messages | Messages | Messaging with file uploads |
| kanvas.messagesTypes | Types | Message type definitions |
| kanvas.roles | Roles | Role management |
| kanvas.customFields | CustomFields | Custom field CRUD |
| kanvas.filesystem | Filesystem | File uploads |
| kanvas.tags | Tags | Tag management |
| kanvas.channels | Channels | Channel management |
| kanvas.follow | Follow | Follow relationships |
| kanvas.agents | Agents | AI agent management |
| kanvas.workflow | Workflow | Workflow automation |
| kanvas.receiver | Receiver | Webhook receivers |
| kanvas.notifications | Notifications | Notification handling |
| kanvas.event | Event | Event management |
Authentication
// Login
const { token, user } = await kanvas.auth.login("agent@example.com", "password");
// Register
const { token, user } = await kanvas.auth.register({
displayname: "My Agent",
email: "agent@example.com",
password: "password",
password_confirmation: "password",
});
// Logout
await kanvas.auth.logout();CRM Operations
// Create a lead
const lead = await kanvas.leads.createLead({
title: "New deal",
people_id: 1,
pipeline_stage_id: 1,
});
// Create a person
const person = await kanvas.people.createPeople({
firstname: "Jane",
lastname: "Doe",
email: "jane@example.com",
});
// Update a person
await kanvas.people.updatePeople(personId, { firstname: "Janet" });Inventory Operations
// Create a product
const product = await kanvas.inventory.createProduct({
input: {
name: "Widget",
slug: "widget",
description: "A great widget",
productsTypes: { id: 1 },
},
});
// Upload a file
const file = await kanvas.filesystem.uploadFile(fileBlob);Direct GraphQL with Apollo Client
For custom queries, use the underlying Apollo Client:
import { gql } from "@apollo/client";
const result = await kanvas.client.query({
query: gql`
query {
leads(first: 10) { data { id title } }
}
`,
fetchPolicy: "no-cache",
});