Recipients
Easily manage SMS recipients with the MailerSend API. Retrieve a list of recipients and their information, and update their status.
Get information about SMS recipients.
Get a list of SMS recipients
Get a list of SMS recipients information with this GET request:
GET https://api.mailersend.com/v1/sms-recipientsRequest parameters
| Query parameter | Type | Required | Limitations | Details |
|---|---|---|---|---|
status | string | no | active, opt_out | |
sms_number_id | string | no | ||
page | int | no | ||
limit | int | no | Min: 10, Max: 100 | Default: 25 |
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsRecipientParams;
$mailersend = new MailerSend(['api_key' => 'key']);
$smsRecipientParams = (new SmsRecipientParams())
->setSmsNumberId('sms_number_id')
->setStatus('opt_out')
->setPage(3)
->setLimit(15);
$smsRecipients = $mailersend->smsRecipient->getAll($smsRecipientParams);import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.recipient.list({
sms_number_id: "sms_number_id",
status: "active",
limit: 10,
page: 1,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));from mailersend import MailerSendClient, SmsRecipientsBuilder
from mailersend.models.sms_recipients import SmsRecipientStatus
ms = MailerSendClient()
request = (SmsRecipientsBuilder()
.sms_number_id("sms-number-id")
.status(SmsRecipientStatus.ACTIVE)
.page(1)
.limit(25)
.build_list_request())
response = ms.sms_recipients.list_sms_recipients(request)package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.SmsRecipientOptions{SmsNumberId: "sms-number-id"}
_, _, err := ms.SmsRecipient.List(context.TODO(), options)
if err != nil {
log.Fatal(err)
}
}import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.recipients.SmsRecipient;
import com.mailersend.sdk.sms.recipients.SmsRecipientList;
public void getSmsRecipients() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
SmsRecipientList list = ms.sms().recipients().getRecipients();
for (SmsRecipient recipient : list.recipients) {
System.out.println(recipient.id);
}
} catch (MailerSendException e) {
e.printStackTrace();
}
}require "mailersend-ruby"
# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new
# Add parameters
ms_sms_recipient.list(page: 1, limit: 10)Responses
Valid
Response Code: 200 OK
Response Headers:
content-type: application/json{
"data": [
{
"id": "62347d2be979fd275c0afd34",
"number": "+1234567890",
"status": "active",
"created_at": "2022-01-01T12:00:0003.000000Z"
},
...
]
}Error
Response Code: 422 Unprocessable EntitySee - Validations errors
Get an SMS recipient
Get information about a specific SMS recipient with this GET request:
GET https://api.mailersend.com/v1/sms-recipients/{sms_recipient_id}Request parameters
| URL parameter | Type | Required | Limitations | Details |
|---|---|---|---|---|
sms_recipient_id | string | yes |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$smsRecipients = $mailersend->smsRecipient->find('sms_recipient_id');import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.recipient.single("sms_recipient_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));from mailersend import MailerSendClient, SmsRecipientsBuilder
ms = MailerSendClient()
request = (SmsRecipientsBuilder()
.sms_recipient_id("recipient-id")
.build_get_request())
response = ms.sms_recipients.get_sms_recipient(request)package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, _, err := ms.SmsRecipient.Get(context.TODO(), "sms-recipient-id")
if err != nil {
log.Fatal(err)
}
}import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.recipients.SmsRecipient;
public void getSmsRecipient() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
SmsRecipient recipient = ms.sms().recipients().getRecipient("recipient id");
System.out.println(recipient.id);
} catch (MailerSendException e) {
e.printStackTrace();
}
}require "mailersend-ruby"
# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new
# Add parameters
ms_sms_recipient.get(sms_recipient_id: 'your-sms-recipient-id')Responses
Valid
Response Code: 200 OK
Response Headers:
content-type: application/json{
"data": {
"id": "62347d2be979fd275c0afd34",
"number": "+1234567890",
"status": "active",
"created_at": "2022-01-01T12:00:00.000000Z",
"sms": [
{
"id": "62347d2be979fd275c0afd33",
"from": "+1234567890",
"to": "+1234567890",
"text": "Lorem Ipsum is simply dummy text",
"status": "delivered",
"segment_count": 1,
"error_type": null,
"error_description": null,
"created_at": "2022-01-01T12:00:00.000000Z"
}
]
}
}Error
Response Code: 404 Not FoundUpdate a single SMS recipient
Update a specific SMS recipient with this PUT request:
PUT https://api.mailersend.com/v1/sms-recipients/{sms_recipient_id}Request parameters
| URL parameter | Type | Required | Limitations | Details |
|---|---|---|---|---|
sms_recipient_id | string | yes |
| Query parameter | Type | Required | Limitations | Details |
|---|---|---|---|---|
status | string | yes | active, opt_out |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$smsRecipients = $mailersend->smsRecipient->update('sms_recipient_id', $status = 'opt_out');import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.recipient.list({
sms_number_id: "sms_number_id",
status: "active",
limit: 10,
page: 1,
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));from mailersend import MailerSendClient, SmsRecipientsBuilder
from mailersend.models.sms_recipients import SmsRecipientStatus
ms = MailerSendClient()
request = (SmsRecipientsBuilder()
.sms_recipient_id("recipient-id")
.build_update_request(SmsRecipientStatus.OPT_OUT))
response = ms.sms_recipients.update_sms_recipient(request)package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.SmsRecipientSettingOptions{
Id: "sms-recipient-id",
Status: "opt_out",
}
_, _, err := ms.SmsRecipient.Update(context.TODO(), options)
if err != nil {
log.Fatal(err)
}
}import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.recipients.SmsRecipient;
public void updateSmsRecipient() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
String status = "opt_out";
SmsRecipient recipient = ms.sms().recipients().updateRecipient("recipient id", status);
System.out.println(recipient.status);
} catch (MailerSendException e) {
e.printStackTrace();
}
}require "mailersend-ruby"
# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new
# Add parameters
ms_sms_recipient.update(sms_recipient_id: 'your-sms-recipient-id', status: 'opt_out')Responses
Valid
Response Code: 200 OK
Response Headers:
content-type: application/json{
"data": {
"id": "62347d2be979fd275c0afd34",
"number": "+1234567890",
"status": "opt_out",
"created_at": "2022-01-01T12:00:0003.000000Z"
}
}Error
Response Code: 422 Unprocessable EntitySee - Validations errors
Activity
Track your messages with the SMS Activity API endpoint. Get a list of activities or view the activity of a single message. Upgrade your communication strategy with MailerSend.
Webhooks
View available webhook events and create, manage and update webhooks with the SMS Webhooks API endpoint. Receive important notifications and optimize workflows.