Skip to main content

JavaScript Quickstart

Build a cStar integration with JavaScript in under 5 minutes. This guide covers installation, setup, listing tickets, creating tickets, and subscribing to real-time events.

1. Install

npm install @cstar.help/js
			

2. Set Up the Client

index.js
import { CStarClient } from '@cstar.help/js';
			
			const cstar = new CStarClient({
			  apiKey: process.env.CSTAR_API_KEY
			});
			

3. Fetch Data

List open tickets with built-in loading and error states.

list-tickets.js
// List open tickets
			const { data: tickets, pagination } = await cstar.tickets.list({
			  status: 'open',
			  page: 1,
			  pageSize: 10
			});
			
			console.log(`Found ${pagination.total} open tickets`);
			
			for (const ticket of tickets) {
			  console.log(`[${ticket.priority}] ${ticket.title}`);
			}
			

4. Create a Resource

Create a new ticket from your application.

create-ticket.js
// Create a new ticket
			const ticket = await cstar.tickets.create({
			  title: 'Login page shows blank screen',
			  priority: 'high',
			  customerName: 'Jane Smith',
			  tags: 'bug,login'
			});
			
			console.log('Created ticket:', ticket.id);
			

5. Real-Time Events

Subscribe to webhook events for real-time updates.

// Listen for webhook events
			import { CStarClient } from '@cstar.help/js';
			
			const cstar = new CStarClient({
			  apiKey: process.env.CSTAR_API_KEY
			});
			
			// Subscribe to real-time events
			const subscription = cstar.subscribe('ticket.*', (event) => {
			  console.log('Event:', event.type, event.data);
			});
			

What's Next?