API Referencev1

JavaScript SDK

The official Odento JavaScript SDK provides a typed, ergonomic interface to the Odento API. Works in Node.js, browsers, and edge runtimes. Full TypeScript support included.

Installation

Requestbash
npm install @odento/sdk

# or with yarn
yarn add @odento/sdk

# or with pnpm
pnpm add @odento/sdk

Initialization

Initialize the SDK with your API key credentials. For server-side applications, load keys from environment variables — never commit them to your codebase.

Requestjavascript
import { Odento } from '@odento/sdk'

const odento = new Odento({
  keyId: process.env.ODENTO_API_KEY_ID,       // ok_live_...
  keySecret: process.env.ODENTO_API_KEY_SECRET, // os_...
})

// Optionally override the base URL (for testing/staging)
const odentoStaging = new Odento({
  keyId: process.env.ODENTO_API_KEY_ID,
  keySecret: process.env.ODENTO_API_KEY_SECRET,
  baseUrl: 'https://staging-api.odento.app',
})

JWT Authentication

For user-facing applications, authenticate with email and password. The SDK automatically stores and refreshes tokens:

Requestjavascript
import { Odento } from '@odento/sdk'

const odento = new Odento()

// Login — SDK stores tokens internally
await odento.auth.login({
  email: 'dr.sharma@dentalkare.in',
  password: 'your-secure-password',
})

// All subsequent calls use the stored access token
// The SDK automatically refreshes when the token expires

Usage Examples

List Patients

Requestjavascript
// List all patients with pagination
const result = await odento.patients.list({
  limit: 10,
  status: 'active',
})

console.log(result.items)
console.log(result.pagination.hasMore)

// Iterate through all pages
let cursor = result.pagination.nextCursor
while (result.pagination.hasMore) {
  const next = await odento.patients.list({ limit: 10, cursor })
  console.log(next.items)
  cursor = next.pagination.nextCursor
}

Create a Patient

Requestjavascript
const patient = await odento.patients.create({
  first_name: 'Priya',
  last_name: 'Sharma',
  email: 'priya.sharma@example.com',
  phone: '+919876543210',
  date_of_birth: '1990-05-15',
  gender: 'female',
  address: {
    street: '12 MG Road',
    city: 'Bengaluru',
    state: 'Karnataka',
    postal_code: '560001',
    country: 'India',
  },
})

console.log(patient.id) // pat_5f8d3a2b1c9e4a7b

Create an Appointment

Requestjavascript
const appointment = await odento.appointments.create({
  patient_id: 'pat_5f8d3a2b1c9e4a7b',
  dentist_id: 'usr_abc123',
  start_time: '2025-01-22T10:00:00Z',
  end_time: '2025-01-22T11:00:00Z',
  type: 'consultation',
  location_id: 'loc_xyz789',
  notes: 'Routine checkup',
})

console.log(appointment.id) // apt_7a3b9c1d2e5f8a4b

Manage Webhooks

Requestjavascript
// Create a webhook endpoint
const webhook = await odento.webhooks.create({
  url: 'https://myapp.com/webhooks/odento',
  events: ['appointment.created', 'invoice.paid'],
  description: 'Production webhook',
})

console.log(webhook.signingSecret) // whsec_... — store this!

Error Handling

The SDK throws typed errors. Catch them by error code to handle specific cases:

Requestjavascript
import { OdentoError } from '@odento/sdk'

try {
  const patient = await odento.patients.create({
    first_name: 'Priya',
    // missing required fields...
  })
} catch (error) {
  if (error instanceof OdentoError) {
    console.log(error.code)    // 'VALIDATION_ERROR'
    console.log(error.message) // 'The request body contains invalid fields.'
    console.log(error.details)  // [{ field: 'email', message: 'Email is required.' }]

    if (error.code === 'RATE_LIMITED') {
      // SDK already retries automatically, but you can add custom logic
      console.log('Rate limited. Retry after:', error.retryAfter)
    }
  } else {
    throw error // re-throw unexpected errors
  }
}

Configuration Options

OptionTypeDefaultDescription
keyIdstring—API key ID (ok_live_*)
keySecretstring—API key secret (os_*)
baseUrlstringapi.odento.appBase URL for API requests
timeoutnumber30000Request timeout in milliseconds
maxRetriesnumber3Max retries for 5xx and 429 errors
autoRefreshbooleantrueAuto-refresh JWT tokens before expiry

Browser Usage

The SDK works in browsers but never expose your API key secret in client-side code. Instead, use JWT authentication with a backend that handles login, or proxy API requests through your own backend:

Requestjavascript
// Browser — use JWT auth (token obtained from your backend)
import { Odento } from '@odento/sdk'

const odento = new Odento({
  accessToken: userAccessToken, // obtained from your backend
})

Was this page helpful?

Help us improve our documentation