MailSlurp logo

Use inbound TXT/SMS

Manage phone and SMS txt messages.

View Markdown Agent setup

MailSlurp supports creation and management of real mobile phone numbers in multiple regions. Phone numbers can receive inbound SMS text messages that can be read and received in code, tests, or online.

sms-basic

Common use for SMS includes testing OTP codes. See the tutorials for examples:

Creating phone numbers

First add a phone plan to your account subscription. Then provision a phone number for the plan in the MailSlurp dashboard or using the API.

Variants

Some regions support phone numbers variants such as Mobile, and Toll Free. These variants affect the type of number that is allocated on our networks. Using variants can improve receiving SMS from short-code numbers.

Create in dashboard

To assign new phone number use the dashboard phone number page. You can select from a range of phone countries and pricing plans.

Create phone

Create phone number programmatically

To enable API phone creation you must first have a paid plan and enable API creation on the phone number overview page in the dashboard.

enable sms

Once enabled you can call the create phone number endpoints:

const phone = await mailslurp.phoneController.createPhoneNumber({
  createPhoneNumberOptions: {
    name: 'Sales inbound',
    phoneCountry: CreatePhoneNumberOptionsPhoneCountryEnum.US,
  }
})
expect(phone.phoneNumber).toContain('+1')

Info. Each create phone number call bills your account for a phone number rental of one month. This is because telecom providers only rent phone numbers for a minimum of one month.

The phone creation endpoint is the API surface for provisioning numbers after API creation is enabled for your account.

POST /phone

Add phone number to your account. Only works if you have already added a plan and an initial phone number in your account and acknowledged the pricing and terms of service by enabling API phone creation.

Create new phone number

Request, parameters, and responses

Request body (required)

CreatePhoneNumberOptions application/json
FieldTypeRequiredDescription
phoneCountryenum: US | GB | AU | CA | EE | HKYes
namestringNo
descriptionstringNo
tagsstring[]No
scheduleenum: MONTHLY | YEARLYNo
phoneNumberEndpointOverridestringNo
phoneNumberVariantenum: LOCAL | MOBILE | TOLL_FREENo
phoneProviderenum: T1 | T2No
phoneLineFilterenum: ANY | OTP_FRIENDLY | NON_VOIPNoLine-quality preference for simple phone number provisioning
Request example
{
  "phoneCountry": "US",
  "name": "Example name",
  "description": "value",
  "tags": [
    "example"
  ],
  "schedule": "MONTHLY",
  "phoneNumberEndpointOverride": "value"
}

Responses

StatusSchemaDescription
200PhoneNumberDtoOK
HTTP and SDK snippets

HTTP

HTTP
POST /phone HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json
Content-Type: application/json

{
  "phoneCountry": "US",
  "name": "Example name",
  "description": "value",
  "tags": [
    "example"
  ],
  "schedule": "MONTHLY",
  "phoneNumberEndpointOverride": "value"
}

cURL

cURL
curl -X POST "https://api.mailslurp.com/phone" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{"phoneCountry":"US","name":"Example name","description":"value","tags":["example"],"schedule":"MONTHLY","phoneNumberEndpointOverride":"value"}'

JavaScript SDK

JavaScript SDK
import { Configuration, PhoneControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const phoneController = new PhoneControllerApi(config);
const request = {
  "createPhoneNumberOptions": {
    "phoneCountry": "US",
    "name": "Example name",
    "description": "value",
    "tags": [
      "example"
    ],
    "schedule": "MONTHLY",
    "phoneNumberEndpointOverride": "value"
  }
};

const result = await phoneController.createPhoneNumber(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.phone_controller_api import PhoneControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    phoneController = PhoneControllerApi(api_client)
    create_phone_number_options = {
      "phoneCountry": "US",
      "name": "Example name",
      "description": "value",
      "tags": [
        "example"
      ],
      "schedule": "MONTHLY",
      "phoneNumberEndpointOverride": "value"
    }
    result = phoneController.create_phone_number(create_phone_number_options)

Listing phone numbers

Phone numbers have an ID and a number. When fetching the phone number use the ID. Use the PhoneControllerApi to manage phone numbers.

const mailslurp = new MailSlurp({ apiKey });
// fetch a phone number (must create phone numbers in the dashboard first)
const { content: [phoneNumber] } = await mailslurp.phoneController.getPhoneNumbers({
  size: 1,
  phoneCountry: GetPhoneNumbersPhoneCountryEnum.US
});
expect(phoneNumber.phoneNumber).toEqual('+19108074451');

You can fetch numbers directly using the getBy methods:

const phoneBy = await mailslurp.phoneController.getPhoneNumberByName({
  name: 'Sales inbound'
})

View SMS messages

In the dashboard you can view TXT message threads in the phones section:

View SMS

Use the SmsControllerApi to view and download SMS messages.

const result = await mailslurp.smsController.getSmsMessagesPaginated({
  phoneNumber: phoneNumber.id
});
expect(result.totalElements).toBeGreaterThan(0);
// content contains array of sms messages
expect(result.content[0].body).toContain('Your code');

You can fetch individual messages using the message's ID.

// fetch a message
const txtMessage = await mailslurp.smsController.getSmsMessage({
  smsId: sms.id // UUID of the SMS message
});
expect(txtMessage.read).toEqual(true);
expect(txtMessage.fromNumber).toEqual('+13252527014');

For tests that need to list, inspect, or parse SMS content after receipt, pair phone-number message listing with direct SMS reads and code extraction.

GET /phone/numbers/{phoneNumberId}/sms

List SMS messages for a phone number

Get SMS messages for a phone number

Request, parameters, and responses

Path parameters

NameTypeRequiredDescription
phoneNumberIdstring:uuidYes

Query parameters

NameTypeRequiredDescription
pageinteger:int32NoOptional page index in SMS list pagination
sizeinteger:int32NoOptional page size in SMS list pagination. Maximum size is 100. Use page index and sort to page through larger results
sortenum: ASC | DESCNoOptional createdAt sort direction ASC or DESCValues: ASC, DESC
unreadOnlybooleanNoOptional filter for unread SMS only. All SMS are considered unread until they are viewed in the dashboard or requested directly
sincestring:date-timeNoOptional filter SMSs received after given date time
beforestring:date-timeNoOptional filter SMSs received before given date time
searchstringNoOptional search filter
favouritebooleanNoOptionally filter results for favourites only

Responses

StatusSchemaDescription
200PageSmsProjectionOK
HTTP and SDK snippets

HTTP

HTTP
GET /phone/numbers/00000000-0000-4000-8000-000000000000/sms?page=value&size=value&sort=ASC HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json

cURL

cURL
curl -X GET "https://api.mailslurp.com/phone/numbers/00000000-0000-4000-8000-000000000000/sms?page=value&size=value&sort=ASC" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json"

JavaScript SDK

JavaScript SDK
import { Configuration, PhoneControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const phoneController = new PhoneControllerApi(config);
const request = {
  "phoneNumberId": "00000000-0000-4000-8000-000000000000",
  "page": null,
  "size": null,
  "sort": "ASC"
};

const result = await phoneController.getSmsByPhoneNumber(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.phone_controller_api import PhoneControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    phoneController = PhoneControllerApi(api_client)
    result = phoneController.get_sms_by_phone_number("00000000-0000-4000-8000-000000000000", page=NaN, size=NaN, sort="ASC")
GET /sms/{smsId}

Get SMS content including body. Expects SMS to exist by ID. For SMS that may not have arrived yet use the WaitForController.

Returns a SMS summary object with content.

Request, parameters, and responses

Path parameters

NameTypeRequiredDescription
smsIdstring:uuidYes

Responses

StatusSchemaDescription
200SmsDtoOK
HTTP and SDK snippets

HTTP

HTTP
GET /sms/00000000-0000-4000-8000-000000000000 HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json

cURL

cURL
curl -X GET "https://api.mailslurp.com/sms/00000000-0000-4000-8000-000000000000" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json"

JavaScript SDK

JavaScript SDK
import { Configuration, SmsControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const smsController = new SmsControllerApi(config);
const request = {
  "smsId": "00000000-0000-4000-8000-000000000000"
};

const result = await smsController.getSmsMessage(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.sms_controller_api import SmsControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    smsController = SmsControllerApi(api_client)
    result = smsController.get_sms_message("00000000-0000-4000-8000-000000000000")
POST /sms/{smsId}/codes

Extract verification codes from an SMS

Extract one-time passcodes and verification tokens from SMS body content. Deterministic `PATTERN` extraction is available now. Use method flags to control fallback behavior for QA.

Request, parameters, and responses

Path parameters

NameTypeRequiredDescription
smsIdstring:uuidYesID of SMS to extract codes from

Request body

ExtractCodesOptions application/json
FieldTypeRequiredDescription
methodenum: AUTO | PATTERN | LLM | OCR | OCR_THEN_LLMNoExtraction strategy for verification codes. Unsupported strategies may fall back when allowFallback is true.
allowFallbackbooleanNoAllow fallback to deterministic pattern extraction when the selected method is unavailable.
minLengthinteger:int32NoMinimum code length to consider. Typical OTP values are between 4 and 8 characters.
maxLengthinteger:int32NoMaximum code length to consider.
maxCandidatesinteger:int32NoMaximum number of code candidates to return. Best candidate is also returned separately.
customPatternsstring[]NoOptional custom regex patterns for code extraction. Each pattern should have either one capture group for the code or match the full code directly.
Request example
{
  "method": "AUTO",
  "allowFallback": true,
  "minLength": 4,
  "maxLength": 10,
  "maxCandidates": 5,
  "customPatterns": [
    "value"
  ]
}

Responses

StatusSchemaDescription
200ExtractCodesResultOK
HTTP and SDK snippets

HTTP

HTTP
POST /sms/00000000-0000-4000-8000-000000000000/codes HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json
Content-Type: application/json

{
  "method": "AUTO",
  "allowFallback": true,
  "minLength": 4,
  "maxLength": 10,
  "maxCandidates": 5,
  "customPatterns": [
    "value"
  ]
}

cURL

cURL
curl -X POST "https://api.mailslurp.com/sms/00000000-0000-4000-8000-000000000000/codes" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{"method":"AUTO","allowFallback":true,"minLength":4,"maxLength":10,"maxCandidates":5,"customPatterns":["value"]}'

JavaScript SDK

JavaScript SDK
import { Configuration, SmsControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const smsController = new SmsControllerApi(config);
const request = {
  "smsId": "00000000-0000-4000-8000-000000000000",
  "extractCodesOptions": {
    "method": "AUTO",
    "allowFallback": true,
    "minLength": 4,
    "maxLength": 10,
    "maxCandidates": 5,
    "customPatterns": [
      "value"
    ]
  }
};

const result = await smsController.getSmsCodes(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.sms_controller_api import SmsControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    smsController = SmsControllerApi(api_client)
    extract_codes_options = {
      "method": "AUTO",
      "allowFallback": True,
      "minLength": 4,
      "maxLength": 10,
      "maxCandidates": 5,
      "customPatterns": [
        "value"
      ]
    }
    result = smsController.get_sms_codes("00000000-0000-4000-8000-000000000000", extract_codes_options)

Send SMS

You can send SMS programmatically or using the dashboard.

await mailslurp.phoneController.sendSmsFromPhoneNumber({
  phoneNumberId: sendingNumber,
  sendPhoneNumberOptions: {
    to: '+14155551212',
    message: 'Hello from Mailslurp'
  }
});

Info. Telecom providers impose some regulations on sending. Only send to numbers that have explicitly consented to being contacted. By default MailSlurp only permits sending to numbers that have initiated contact with you. To remove this restriction contact support.

Send a test message

Use the normal send endpoint with a controlled destination and content in test environments:

await mailslurp.phoneController.sendSmsFromPhoneNumber({
  phoneNumberId: sendingNumber,
  sendPhoneNumberOptions: {
    to: '+14155551212',
    message: 'Hello from Mailslurp'
  }
});

Use phone-scoped sending when the sender number matters. For a received inbound message, replies can be sent from the number that received it.

POST /phone/numbers/{phoneNumberId}/sms

Send TXT message from a phone number

Send SMS from a phone number

Request, parameters, and responses

Path parameters

NameTypeRequiredDescription
phoneNumberIdstring:uuidYes

Request body (required)

SmsSendOptions application/json
FieldTypeRequiredDescription
tostringYes
bodystringYes
Request example
{
  "to": "+15551234567",
  "body": "Hello from MailSlurp"
}

Responses

StatusSchemaDescription
200SentSmsDtoOK
HTTP and SDK snippets

HTTP

HTTP
POST /phone/numbers/00000000-0000-4000-8000-000000000000/sms HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json
Content-Type: application/json

{
  "to": "+15551234567",
  "body": "Hello from MailSlurp"
}

cURL

cURL
curl -X POST "https://api.mailslurp.com/phone/numbers/00000000-0000-4000-8000-000000000000/sms" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{"to":"+15551234567","body":"Hello from MailSlurp"}'

JavaScript SDK

JavaScript SDK
import { Configuration, PhoneControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const phoneController = new PhoneControllerApi(config);
const request = {
  "phoneNumberId": "00000000-0000-4000-8000-000000000000",
  "smsSendOptions": {
    "to": "+15551234567",
    "body": "Hello from MailSlurp"
  }
};

const result = await phoneController.sendSmsFromPhoneNumber(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.phone_controller_api import PhoneControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    phoneController = PhoneControllerApi(api_client)
    sms_send_options = {
      "to": "+15551234567",
      "body": "Hello from MailSlurp"
    }
    result = phoneController.send_sms_from_phone_number("00000000-0000-4000-8000-000000000000", sms_send_options)
POST /sms/{smsId}/reply

Send a reply to a received SMS message. Replies are sent from the receiving number.

Reply to an SMS message.

Request, parameters, and responses

Path parameters

NameTypeRequiredDescription
smsIdstring:uuidYes

Request body (required)

SmsReplyOptions application/json
FieldTypeRequiredDescription
bodystringYes
Request example
{
  "body": "Hello from MailSlurp"
}

Responses

StatusSchemaDescription
200SentSmsDtoOK
HTTP and SDK snippets

HTTP

HTTP
POST /sms/00000000-0000-4000-8000-000000000000/reply HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json
Content-Type: application/json

{
  "body": "Hello from MailSlurp"
}

cURL

cURL
curl -X POST "https://api.mailslurp.com/sms/00000000-0000-4000-8000-000000000000/reply" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{"body":"Hello from MailSlurp"}'

JavaScript SDK

JavaScript SDK
import { Configuration, SmsControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const smsController = new SmsControllerApi(config);
const request = {
  "smsId": "00000000-0000-4000-8000-000000000000",
  "smsReplyOptions": {
    "body": "Hello from MailSlurp"
  }
};

const result = await smsController.replyToSmsMessage(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.sms_controller_api import SmsControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    smsController = SmsControllerApi(api_client)
    sms_reply_options = {
      "body": "Hello from MailSlurp"
    }
    result = smsController.reply_to_sms_message("00000000-0000-4000-8000-000000000000", sms_reply_options)

Wait for new SMS messages

Use the WaitForControllerApi waitForSms methods to hold a connection open until an expected count of SMS messages is present in a phone number

// wait for the latest unread sms
const [sms] = await mailslurp.waitController.waitForSms({
  waitForSmsConditions: {
    count: 1,
    unreadOnly: true,
    phoneNumberId: phoneNumber.id,
    timeout: 30_000
  }
});
// extract a code from body with regex
expect(sms.body).toContain('Your code: 123');
const [, code] = /.+:\s([0-9]{3})/.exec(sms.body);
expect(code).toEqual('123');

This is an important technique for SMS based testing. See the testing guide for more information.

Define BLOCK and ALLOW rules

You can define rules for which phone numbers can send SMS to your phone numbers. This is done using rulesets. You can create rulesets that block or allow SMS from specific phone numbers or patterns to prevent any unwanted spam. An example looks like this:

// block SMS spam except for known numbers
const blockAll = await rulesetController.createNewRuleset({
  phoneId: undefined, // account wide block
  createRulesetOptions: {
    action: 'BLOCK',
    scope: 'RECEIVING_SMS',
    target: '*'
  }
})
const allowSpecific = await rulesetController.createNewRuleset({
  phoneId: undefined, // account wide permit
  createRulesetOptions: {
    action: 'ALLOW',
    scope: 'RECEIVING_SMS',
    target: '+1234567890' // replace with a known number
  }
})

In the app dashboard the interface can be found in the automations tab on the phone number overview:

block-spam-sms.jpeg

When a test triggers an OTP or MFA flow, wait for the expected SMS instead of sleeping for a fixed delay.

POST /waitForSms

Wait for an SMS message to match the provided filter conditions such as body contains keyword.

Generic waitFor method that will wait until a phone number meets given conditions or return immediately if already met

Request, parameters, and responses

Request body (required)

WaitForSmsConditions application/json
FieldTypeRequiredDescription
phoneNumberIdstring:uuidYesID of phone number to search within and apply conditions to. Essentially filtering the SMS found to give a count.
limitinteger:int32NoLimit results
countinteger:int64YesNumber of results that should match conditions. Either exactly or at least this amount based on the `countType`. If count condition is not met and the timeout has not been reached the `waitFor` method will retry the operation.
delayTimeoutinteger:int64NoMax time in milliseconds to wait between retries if a `timeout` is specified.
timeoutinteger:int64YesMax time in milliseconds to retry the `waitFor` operation until conditions are met.
unreadOnlybooleanNoApply conditions only to **unread** SMS. All SMS messages begin with `read=false`. An SMS is marked `read=true` when an `SMS` has been returned to the user at least once. For example you have called `getSms`, or you have viewed the SMS in the dashboard.
countTypeenum: EXACTLY | ATLEASTNoHow result size should be compared with the expected size. Exactly or at-least matching result?
matchesSmsMatchOption[]NoConditions that should be matched for an SMS to qualify for results. Each condition will be applied in order to each SMS within a phone number to filter a result list of matching SMSs you are waiting for.
sortDirectionenum: ASC | DESCNoDirection to sort matching SMSs by created time
sincestring:date-timeNoISO Date Time earliest time of SMS to consider. Filter for matching SMSs that were received after this date
beforestring:date-timeNoISO Date Time latest time of SMS to consider. Filter for matching SMSs that were received before this date
Request example
{
  "phoneNumberId": "00000000-0000-4000-8000-000000000000",
  "count": 1,
  "timeout": 1,
  "limit": 1,
  "delayTimeout": 1,
  "unreadOnly": true
}

Responses

StatusSchemaDescription
200SmsPreview[]OK
HTTP and SDK snippets

HTTP

HTTP
POST /waitForSms HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json
Content-Type: application/json

{
  "phoneNumberId": "00000000-0000-4000-8000-000000000000",
  "count": 1,
  "timeout": 1,
  "limit": 1,
  "delayTimeout": 1,
  "unreadOnly": true
}

cURL

cURL
curl -X POST "https://api.mailslurp.com/waitForSms" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{"phoneNumberId":"00000000-0000-4000-8000-000000000000","count":1,"timeout":1,"limit":1,"delayTimeout":1,"unreadOnly":true}'

JavaScript SDK

JavaScript SDK
import { Configuration, WaitForControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const waitForController = new WaitForControllerApi(config);
const request = {
  "waitForSmsConditions": {
    "phoneNumberId": "00000000-0000-4000-8000-000000000000",
    "count": 1,
    "timeout": 1,
    "limit": 1,
    "delayTimeout": 1,
    "unreadOnly": true
  }
};

const result = await waitForController.waitForSms(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.wait_for_controller_api import WaitForControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    waitForController = WaitForControllerApi(api_client)
    wait_for_sms_conditions = {
      "phoneNumberId": "00000000-0000-4000-8000-000000000000",
      "count": 1,
      "timeout": 1,
      "limit": 1,
      "delayTimeout": 1,
      "unreadOnly": True
    }
    result = waitForController.wait_for_sms(wait_for_sms_conditions)
POST /waitForLatestSms

Wait for the latest SMS message to match the provided filter conditions such as body contains keyword.

Wait until a phone number meets given conditions or return immediately if already met

Request, parameters, and responses

Request body (required)

WaitForSingleSmsOptions application/json
FieldTypeRequiredDescription
phoneNumberIdstring:uuidYes
timeoutinteger:int64Yes
unreadOnlybooleanNo
beforestring:date-timeNo
sincestring:date-timeNo
sortDirectionenum: ASC | DESCNo
delayinteger:int64No
Request example
{
  "phoneNumberId": "00000000-0000-4000-8000-000000000000",
  "timeout": 1,
  "unreadOnly": true,
  "before": "2026-06-21T00:00:00.000Z",
  "since": "2026-06-21T00:00:00.000Z",
  "sortDirection": "ASC"
}

Responses

StatusSchemaDescription
200SmsDtoOK
HTTP and SDK snippets

HTTP

HTTP
POST /waitForLatestSms HTTP/1.1
Host: api.mailslurp.com
x-api-key: YOUR_API_KEY
Accept: application/json
Content-Type: application/json

{
  "phoneNumberId": "00000000-0000-4000-8000-000000000000",
  "timeout": 1,
  "unreadOnly": true,
  "before": "2026-06-21T00:00:00.000Z",
  "since": "2026-06-21T00:00:00.000Z",
  "sortDirection": "ASC"
}

cURL

cURL
curl -X POST "https://api.mailslurp.com/waitForLatestSms" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  --data '{"phoneNumberId":"00000000-0000-4000-8000-000000000000","timeout":1,"unreadOnly":true,"before":"2026-06-21T00:00:00.000Z","since":"2026-06-21T00:00:00.000Z","sortDirection":"ASC"}'

JavaScript SDK

JavaScript SDK
import { Configuration, WaitForControllerApi } from "mailslurp-client";

const config = new Configuration({ apiKey: "YOUR_API_KEY" });
const waitForController = new WaitForControllerApi(config);
const request = {
  "waitForSingleSmsOptions": {
    "phoneNumberId": "00000000-0000-4000-8000-000000000000",
    "timeout": 1,
    "unreadOnly": true,
    "before": "2026-06-21T00:00:00.000Z",
    "since": "2026-06-21T00:00:00.000Z",
    "sortDirection": "ASC"
  }
};

const result = await waitForController.waitForLatestSms(request);

Python SDK

Python SDK
import mailslurp_client
from mailslurp_client.api.wait_for_controller_api import WaitForControllerApi

configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = "YOUR_API_KEY"

with mailslurp_client.ApiClient(configuration) as api_client:
    waitForController = WaitForControllerApi(api_client)
    wait_for_single_sms_options = {
      "phoneNumberId": "00000000-0000-4000-8000-000000000000",
      "timeout": 1,
      "unreadOnly": True,
      "before": "2026-06-21T00:00:00.000Z",
      "since": "2026-06-21T00:00:00.000Z",
      "sortDirection": "ASC"
    }
    result = waitForController.wait_for_latest_sms(wait_for_single_sms_options)

Use SMS webhooks

Have SMS messages sent via HTTP POST to your server with TXT Webhooks

// create a webhook for a phone number to have new SMS sent to your server
const webhook = await mailslurp.webhookController.createWebhookForPhoneNumber({
  phoneNumberId: phoneNumber.id,
  createWebhookOptions: {
    eventName: CreateWebhookOptionsEventNameEnum.NEW_SMS,
    url: 'https://myserver.com',
    name: 'Process SMS'
  }
});