Samva
Samva
DashboardAPISamva DocumentationQuickstart GuideAuthentication

SDKs & ToolsTypeScript SDKREST APIPostman Collection
SDKs & Tools

TypeScript SDK

Official TypeScript/JavaScript SDK for Samva API

The official TypeScript SDK provides a type-safe, modern interface for integrating with Samva's messaging platform.

Installation

npm install samva

Or with your preferred package manager:

# yarn
yarn add samva

# bun
bun add samva

# pnpm
pnpm add samva

Quick Start

import { createSamvaClient } from 'samva';

const samva = createSamvaClient({
  apiKey: process.env.SAMVA_API_KEY!
});

// Send an email
const emailResult = await samva.email.send({
  body: {
    to: 'user@example.com',
    subject: 'Welcome to Samva',
    htmlContent: '<h1>Hello!</h1><p>Welcome to our platform.</p>',
    textContent: 'Hello! Welcome to our platform.'
  }
});

console.log('Email sent:', emailResult.data?.id);

// Send SMS
const smsResult = await samva.sms.send({
  body: {
    to: '+14155552671',
    message: 'Your verification code is 123456'
  }
});

console.log('SMS sent:', smsResult.data?.id);

Features

  • Type-Safe: Full TypeScript support with auto-completion
  • Auto-Generated: Built from our OpenAPI specification
  • Modern: Async/await support throughout
  • Reliable: Automatic retries for transient failures
  • Lightweight: Minimal dependencies

API Methods

Email

// Send email
await samva.email.send({
  body: {
    to: 'user@example.com',
    subject: 'Hello',
    htmlContent: '<p>Hi there!</p>'
  }
});

// List email templates
const templates = await samva.email.listTemplates({});

// Get email stats
const stats = await samva.email.getStats({
  query: { startDate: '2024-01-01' }
});

SMS

// Send SMS
await samva.sms.send({
  body: {
    to: '+14155552671',
    message: 'Your code is 123456'
  }
});

// Get SMS stats
const stats = await samva.sms.getStats({});

WhatsApp

// Send WhatsApp message
await samva.whatsapp.send({
  body: {
    to: '+14155552671',
    message: 'Hello from Samva!'
  }
});

// Send template message
await samva.whatsapp.sendTemplate({
  body: {
    to: '+14155552671',
    templateId: 'welcome_template',
    variables: { name: 'John' }
  }
});

Messages

// List all messages
const messages = await samva.messages.list({
  query: { channel: 'email', limit: 20 }
});

// Get message by ID
const message = await samva.messages.get({
  path: { id: 'msg_123' }
});

// Get message events
const events = await samva.messages.getEvents({
  path: { id: 'msg_123' }
});

Error Handling

const result = await samva.email.send({
  body: {
    to: 'user@example.com',
    subject: 'Test',
    textContent: 'Hello'
  }
});

if (result.error) {
  console.error('Failed to send:', result.error.message);
} else {
  console.log('Sent:', result.data?.id);
}

Configuration Options

const samva = createSamvaClient({
  apiKey: process.env.SAMVA_API_KEY!,
  // Optional: Override base URL for testing
  baseUrl: 'https://samva.app/api'
});

Environment Variables

We recommend storing your API key in environment variables:

# .env
SAMVA_API_KEY=sk_live_your_api_key_here
import { createSamvaClient } from 'samva';

const samva = createSamvaClient({
  apiKey: process.env.SAMVA_API_KEY!
});

Next Steps

API Reference

Complete API documentation

Quickstart Guide

Send your first message

REST API

Direct REST API usage

SDKs & Tools

Official SDKs and developer tools for Samva API

REST API

Direct REST API integration guide for Samva

On this page

InstallationQuick StartFeaturesAPI MethodsEmailSMSWhatsAppMessagesError HandlingConfiguration OptionsEnvironment VariablesNext Steps