Contents

SDKs & examples

Node.js SDK, NestJS, Next.js, PHP, Laravel and cURL.

Node.js SDK

@sms21/node has no runtime dependencies (Node.js 20.3+), full TypeScript types, typed errors, safe automatic retries with idempotency keys, and webhook verification.

Terminal
npm install @sms21/node
TypeScript
import { Sms21, RateLimitError } from '@sms21/node';

const sms21 = new Sms21({ apiKey: process.env.SMS21_API_KEY });

const { requestId } = await sms21.otp.send({ mobile: '919876543210', purpose: 'login' });
await sms21.otp.verify({ requestId, otp });

await sms21.sms.send({ to: '919876543210', templateId: 'tmpl_…', variables: { order: '1042' } });
await sms21.whatsapp.sendTemplate({ to: '919876543210', templateId: 'wtpl_…' });
const message = await sms21.messages.get('msg_…');
const wallet = await sms21.wallet.get();
OptionDefault
apiKeySMS21_API_KEY
baseUrlSMS21_BASE_URL or https://api.sms21.in/v1
timeoutMs30000 per attempt
maxRetries2 (only failures that cannot cause a second send)
appInfoAppended to the User-Agent, e.g. auth-pay2all/2.3.0

Framework examples

Complete, tested examples live in the SMS21 repository under examples/:

StackPathIncludes
cURLexamples/curlEvery endpoint; an OTP flow script; OpenSSL signature check
Node.jsexamples/nodeOTP login CLI, SMS with status tracking, webhook server
NestJSexamples/nestjsGlobal client module, OTP login controller, raw-body webhook controller
Next.jsexamples/nextjsServer-only client, OTP route handlers and form, webhook route
PHPexamples/phpDependency-free cURL client with safe retries, webhook verification
Laravelexamples/laravelService provider, OTP login controller, signature middleware, queued webhook job

Other languages

  • Generate a client from the OpenAPI 3.1 document (for example with openapi-generator), or call the REST API directly.
  • Whatever you use, follow the same rules as the SDK: send idempotency keys, retry only failures that cannot send twice, never retry OTP verification, and verify webhook signatures on the raw body.