Send SMS
Send transactional SMS messages globally using the YourSend API.
Basic SMS
send-sms.ts
import { YourSend } from 'yoursend';
const ys = new YourSend({ apiKey: 'ys_live_...' });
await ys.send({
channel: 'sms',
to: '+14155551234',
body: 'Your order #1234 has shipped! Track it here: https://track.example.com/1234',
});OTP via SMS
Send a one-time password via SMS. Omit body and template_id and YourSend generates a 6-digit code automatically.
otp-sms.ts
// No body/template_id → YourSend sends an OTP code
const otp = await ys.send({
channel: 'sms',
to: '+14155551234',
});
// Later, verify the user-provided code
const result = await ys.check({
message_id: otp.message_id,
code: '123456', // user-provided code
});
console.log(result.verified); // true or falseParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| channel | string | Yes | "sms" |
| to | string | Yes | Phone number in E.164 format (+1...) |
| body | string | Yes* | Message content (max 1600 chars; longer messages are split) |
| template_id | string | Yes* | Template ID (alternative to body) |
| data | object | No | Merge-tag values for templates ({{name}}, etc.) |
* Provide either body or template_id. Omit both to send an OTP code.