Send SMS
Send transactional SMS messages globally using the YourSend API.
Basic SMS
send-sms.ts
import { YourSend } from 'yoursend';
const ys = new YourSend('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. YourSend generates a 6-digit code automatically.
otp-sms.ts
const { data } = await ys.send({
channel: 'sms',
to: '+14155551234',
otp: true,
});
// Later, verify the code
const { data: result } = await ys.check({
message_id: data.message_id,
code: '123456', // user-provided code
});
console.log(result.valid); // 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 480 chars) |
| otp | boolean | No | Set to true to send an OTP code |
| template_id | string | Yes* | Template ID (alternative to body) |
| tags | object | No | Merge tag values |
* Either body, template_id, or otp: true is required.