Skip to content

Official JavaScript/TypeScript SDK for Karma Common API

License

Notifications You must be signed in to change notification settings

karmadev/karma-api-js

Repository files navigation

@karmalicious/karma-api-js

Official JavaScript/TypeScript SDK for the Karma Common API.

Installation

npm install @karmalicious/karma-api-js
# or
yarn add @karmalicious/karma-api-js

Quick Start

import { Configuration, InventoryApi } from '@karmalicious/karma-api-js'

// Initialize configuration
const config = new Configuration({
  basePath: 'https://common-api.karmalicious.com',
  apiKey: 'karma_live_your_api_key_here',
  headers: {
    'X-API-Key': 'karma_live_your_api_key_here'
  }
})

// Create API instances
const inventoryApi = new InventoryApi(config)

// Use the API
async function getInventory() {
  try {
    const response = await inventoryApi.getInventoryItems({
      locationId: 100,
      page: 1,
      limit: 50
    })
    console.log(response)
  } catch (error) {
    console.error('Error fetching inventory:', error)
  }
}

getInventory()

Available APIs

  • InventoryApi - Menu items, products, and modifiers
  • OrdersApi - Customer orders and order management
  • SchedulesApi - Operating hours and special schedules
  • ChannelsApi - Sales channels (dine-in, takeaway, delivery)
  • MenuLayoutsApi - Menu structure and organization
  • WebhooksApi - Webhook subscriptions and event notifications
  • ApiKeysApi - Authentication keys and permissions
  • VariantGroupsApi - Product options and modifiers
  • CustomTagsApi - Labels and categorization
  • CoursingsApi - Multi-course meal sequencing
  • AlertsApi - System notifications and warnings
  • TablesApi - Restaurant table management
  • TableGroupsApi - Table grouping and floor plans
  • LocationMapsApi - Floor plans and seating layouts
  • TabsApi - Customer tabs and running bills
  • TerminalsApi - Payment terminal management
  • VouchersApi - Discount vouchers and promotions
  • ArticlesApi - Changelog and release notes

Authentication

All API requests require an API key. You can generate API keys through the Karma Merchant Dashboard.

const config = new Configuration({
  basePath: 'https://common-api.karmalicious.com',
  headers: {
    'X-API-Key': 'your_api_key_here'
  }
})

Error Handling

import { ResponseError } from '@karmalicious/karma-api-js'

try {
  const response = await inventoryApi.getInventoryItems({ locationId: 100 })
} catch (error) {
  if (error instanceof ResponseError) {
    const errorBody = await error.response.json()
    console.error('API Error:', errorBody)
  } else {
    console.error('Unexpected error:', error)
  }
}

TypeScript Support

This SDK is written in TypeScript and provides full type definitions for all API endpoints and models.

import { InventoryItem, CreateOrderRequest } from '@karmalicious/karma-api-js'

const item: InventoryItem = {
  id: 123,
  title: 'Burger',
  basePrice: 9900, // prices in cents
  // ... fully typed!
}

Environments

// Production
const prodConfig = new Configuration({
  basePath: 'https://common-api.karmalicious.com',
  headers: { 'X-API-Key': 'karma_live_...' }
})

// Development
const devConfig = new Configuration({
  basePath: 'https://common-api-dev.karmalicious.com',
  headers: { 'X-API-Key': 'karma_dev_...' }
})

// Local
const localConfig = new Configuration({
  basePath: 'http://localhost:8080',
  headers: { 'X-API-Key': 'karma_dev_...' }
})

Documentation

Full API documentation is available at:

License

MIT

Support

For support, email dev@karmalicious.com or visit our GitHub repository.

About

Official JavaScript/TypeScript SDK for Karma Common API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •