Recipients

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-recipients

Request parameters

Query parameterTypeRequiredLimitationsDetails
statusstringnoactive, opt_out
sms_number_idstringno
pageintno
limitintnoMin: 10, Max: 100Default: 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);

More examplesopen in new window

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));

More examplesopen in new window

from mailersend import sms_recipients

api_key = "API key here"

mailer = sms_recipients.NewSmsRecipients(api_key)

#Request parameters
sms_number_id = "9pq3enl6842vwrzx"
status = "active"

print(mailer.get_recipients(status=status, sms_number_id=sms_number_id))

More examplesopen in new window

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)
	}
}

More examplesopen in new window

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();
    }
}

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new

# Add parameters
ms_sms_recipient.list(page: 1, limit: 10)

More examplesopen in new window

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 Entity

See - 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 parameterTypeRequiredLimitationsDetails
sms_recipient_idstringyes
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsRecipients = $mailersend->smsRecipient->find('sms_recipient_id');

More examplesopen in new window

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));

More examplesopen in new window

from mailersend import sms_recipients

api_key = "API key here"

mailer = sms_recipients.NewSmsRecipients(api_key)

#Request parameters
sms_recipient_id = "627e756fd30078fb2208cc87"

print(mailer.get_recipient(sms_recipient_id))

More examplesopen in new window

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)
	}
}

More examplesopen in new window

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();
    }
}

More examplesopen in new window

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')

More examplesopen in new window

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 Found

Update 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 parameterTypeRequiredLimitationsDetails
sms_recipient_idstringyes
Query parameterTypeRequiredLimitationsDetails
statusstringyesactive, opt_out
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsRecipients = $mailersend->smsRecipient->update('sms_recipient_id', $status = 'opt_out');

More examplesopen in new window

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));

More examplesopen in new window

from mailersend import sms_recipients

api_key = "API key here"

mailer = sms_recipients.NewSmsRecipients(api_key)

#Request parameters
sms_recipient_id = "627e756fd30078fb2208cc87"
status = "opt_out"

print(mailer.update_recipient(sms_recipient_id, status))

More examplesopen in new window

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)
	}
}

More examplesopen in new window

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();
    }
}

More examplesopen in new window

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')

More examplesopen in new window

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 Entity

See - Validations errors

Last Updated: