JavaScript SDK

JavaScript SDK

Use FeedbackKit with vanilla JavaScript, or any framework. Lightweight and framework-agnostic.

Lightweight

Only 5KB gzipped

Framework Agnostic

Works with any framework

Modern ES6+

Promise-based API

TypeScript

Full type definitions

Installation

npm install @feedbackkit/js

Basic Usage

Initialize the SDK

Set up the FeedbackKit client with your API key

import { FeedbackKit } from '@feedbackkit/widget';

// Initialize with your API key
const feedbackkit = new FeedbackKit('feedbackkit_sk_your_api_key_here', {
  baseUrl: 'https://api.feedbackkit.io',
  timeout: 10000
});

Feedback API

Submit Feedback

// Submit feedback
const result = await feedbackkit.feedback.submit({
  projectId: 'proj_abc123',
  type: 'bug',
  priority: 'high',
  title: 'Login button not working',
  description: 'Users cannot log in on mobile devices',
  screenshot: 'data:image/png;base64,...', // optional
  metadata: {
    browser: 'Chrome 120.0.0',
    viewport: '375x667',
    url: 'https://myapp.com/login'
  }
});

console.log('Feedback ID:', result.id);
console.log('Status:', result.status);

Get Feedback Stats

// Get feedback statistics
const stats = await feedbackkit.feedback.getStats('proj_abc123');

console.log('Total feedback:', stats.totalFeedback);
console.log('Bug reports:', stats.bugReports);
console.log('Feature requests:', stats.featureRequests);

Project API

Create Project

// Create a new feedback project
const project = await feedbackkit.projects.create({
  name: 'My App Feedback',
  settings: {
    description: 'Collect feedback for our web application',
    allowAnonymous: true,
    requireScreenshot: false,
    autoAssign: true
  }
});

console.log('Project ID:', project.id);
console.log('API Key:', project.apiKey);

Get Project Feedback

// Get project feedback
const { feedback, pagination } = await feedbackkit.feedback.get('proj_abc123', {
  status: 'open',
  limit: 10,
  offset: 0
});

feedback.forEach(item => {
  console.log(`${item.type}: ${item.title}`);
});

Webhooks API

Create Webhook

// Create a webhook endpoint
const webhook = await feedbackkit.webhooks.create({
  projectId: 'proj_abc123',
  url: 'https://your-app.com/webhooks/feedback',
  events: ['feedback.created', 'feedback.updated'],
  secret: 'your-webhook-secret'
});

console.log('Webhook created:', webhook.id);

List Webhooks

// Get project webhooks
const { webhooks } = await feedbackkit.webhooks.list('proj_abc123');

webhooks.forEach(webhook => {
  console.log(`${webhook.url}: ${webhook.events.join(', ')}`);
});

Error Handling

Handling API Errors

try {
  const result = await feedbackkit.feedback.submit({
    projectId: 'proj_abc123',
    type: 'bug',
    title: 'Login issue',
    description: 'Cannot log in'
  });
  
  console.log('Success:', result);
} catch (error) {
  if (error.code === 'RATE_LIMIT_EXCEEDED') {
    console.log('Rate limit exceeded, try again later');
  } else if (error.code === 'INVALID_EMAIL') {
    console.log('Please provide a valid email address');
  } else {
    console.log('Error:', error.message);
  }
}

Configuration Options

OptionTypeDefaultDescription
baseUrlstringhttps://api.feedbackkit.ioAPI base URL
timeoutnumber10000Request timeout in ms
retriesnumber3Number of retry attempts
debugbooleanfalseEnable debug logging