Skip to main content

JavaScript SDK

@cstar.help/js is the core client library. It works in Node.js, Deno, Bun, and browsers — anywhere with fetch. React and Svelte SDKs build on top of this.

Installation

npm install @cstar.help/js
			

If you're using @cstar.help/react or @cstar.help/svelte, you already have this — it's included automatically as a dependency.

Initialization

client.js
import { CStarClient } from '@cstar.help/js';
			
			const cstar = new CStarClient({
			  apiKey: 'sk_live_your_key',
			  // Optional: override base URL (defaults to https://app.cstar.help)
			  // baseUrl: 'https://custom-domain.com'
			});
			

Tickets

// List tickets with filters
			const { data, pagination } = await cstar.tickets.list({
			  status: 'open',
			  priority: 'high',
			  page: 1,
			  pageSize: 20
			});
			
			// Get a single ticket (includes messages)
			const ticket = await cstar.tickets.get('ticket-uuid');
			
			// Create a ticket
			const newTicket = await cstar.tickets.create({
			  title: 'Bug report: login page',
			  priority: 'high',
			  customerName: 'Jane Smith'
			});
			
			// Update a ticket
			await cstar.tickets.update('ticket-uuid', {
			  status: 'resolved'
			});
			
			// Delete a ticket
			await cstar.tickets.delete('ticket-uuid');
			

Customers

// List customers
			const { data } = await cstar.customers.list({
			  status: 'active',
			  search: 'jane'
			});
			
			// Get customer details
			const customer = await cstar.customers.get('customer-uuid');
			
			// Create a customer
			const newCustomer = await cstar.customers.create({
			  name: 'Jane Smith',
			  email: 'jane@example.com',
			  tags: 'vip,enterprise'
			});
			
			// Update a customer
			await cstar.customers.update('customer-uuid', {
			  sentiment: 'positive'
			});
			

Articles

// List published articles
			const { data } = await cstar.articles.list({
			  status: 'published',
			  category: 'Getting Started'
			});
			
			// Get an article
			const article = await cstar.articles.get('article-uuid');
			
			// Create an article
			const draft = await cstar.articles.create({
			  title: 'How to reset your password',
			  content: '# Password Reset\n\nFollow these steps...',
			  category: 'Account',
			  status: 'draft'
			});
			
			// Publish an article
			await cstar.articles.update('article-uuid', {
			  status: 'published',
			  isPublic: true
			});
			

Messages

// List messages for a ticket
			const messages = await cstar.tickets.messages.list('ticket-uuid');
			
			// Add a message
			await cstar.tickets.messages.create('ticket-uuid', {
			  content: 'Thanks for reaching out! Let me look into this.',
			  sender: 'agent',
			  senderName: 'Bob (Support)'
			});
			

Webhooks

// List webhooks
			const webhooks = await cstar.webhooks.list();
			
			// Create a webhook
			const webhook = await cstar.webhooks.create({
			  name: 'Slack Integration',
			  url: 'https://your-app.com/webhook',
			  events: 'ticket.created,ticket.closed'
			});
			
			// Save the secret! Only shown once.
			console.log('Webhook secret:', webhook.secret);
			
			// Trigger a test event
			await cstar.webhooks.triggerTest('ticket.created');
			

Real-Time Subscriptions

// Subscribe to all ticket events
			const sub = cstar.subscribe('ticket.*', (event) => {
			  console.log(event.type);  // 'ticket.created', 'ticket.updated', etc.
			  console.log(event.data);  // The ticket object
			});
			
			// Subscribe to specific events
			cstar.subscribe('ticket.created', (event) => {
			  sendSlackNotification(`New ticket: ${event.data.title}`);
			});
			
			// Unsubscribe
			sub.unsubscribe();
			

Error Handling

import { CStarError } from '@cstar.help/js';
			
			try {
			  await cstar.tickets.create({ /* missing title */ });
			} catch (err) {
			  if (err instanceof CStarError) {
			    console.log(err.code);     // 'parameter_missing'
			    console.log(err.message);  // 'title is required'
			    console.log(err.status);   // 400
			    console.log(err.param);    // 'title'
			  }
			}