Messages
SMS Messages are resources that are created from a single SMS API request.
Get a list of SMS messages
Get a list of SMS messages information with this GET
request:
GET https://api.mailersend.com/v1/sms-messages
Request parameters
Query parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
page | int | no | ||
limit | int | no | Min: 10 , Max: 100 | Default: 25 |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$smsMessages = $mailersend->smsMessage->getAll($page = 1, $limit = 10);
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.message.list({
limit: 10,
page: 1
})
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import sms_messages
api_key = "API key here"
mailer = sms_messages.NewSmsMessages(api_key)
print(mailer.get_messages())
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.ListSmsMessageOptions{
Limit: 10,
}
_, _, err := ms.SmsMessage.List(ctx, options)
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailsend.sdk.sms.messages.SmsMessageList;
import com.mailsend.sdk.sms.messages.SmsMessage;
public void getSmsMessages() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
SmsMessageList list = ms.sms().messages().getMessages();
for (SmsMessage message : list.messages) {
System.out.println(message.id);
System.out.println(message.text);
}
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
# Intialize the SMS Messages class
ms_sms_messages = Mailersend::SMSMessages.new
# Add parameters
ms_sms_messages.list(page: 1, limit: 10)
Responses
Valid
Response Code: 200 OK
Response Headers:
content-type: application/json
{
"data": [
{
"id": "6203a0cc00033b7d341d0f52",
"from": "+19191234567",
"to": [
"+19199876543"
],
"text": "Hello world",
"paused": false,
"created_at": "2022-01-01T12:00:00.000000Z"
},
...
]
}
Error
Response Code: 422 Unprocessable Entity
See - Validations errors
Get an SMS message
Get a single SMS message.
GET https://api.mailersend.com/v1/sms-messages/{sms_message_id}
Request parameters
URL parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
sms_message_id | string | yes |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$smsMessage = $mailersend->smsMessage->find('sms_message_id');
import 'dotenv/config';
import { MailerSend } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.sms.message.single("sms_message_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import sms_messages
api_key = "API key here"
#Request parameters
sms_message_id = "627e756fd30078fb2208cc87"
mailer = sms_messages.NewSmsMessages(api_key)
print(mailer.get_message(sms_message_id))
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.SmsMessage.Get(ctx, "sms-message-id")
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailsend.sdk.sms.messages.SmsMessage;
public void getSmsMessage() {
MailerSend ms = new MailerSend();
ms.setToken("mailersend token");
try {
SmsMessage message = ms.sms().messages().getMessage("message id");
System.out.println(message.id);
System.out.println(message.text);
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
# Intialize the SMS Messages class
ms_sms_messages = Mailersend::SMSMessages.new
# Add parameters
ms_sms_messages.get_single_route(sms_message_id: 'your-sms-message-id')
Responses
Valid
Response key | Type | Details |
---|---|---|
data.sms.* | object[] | Will include sms data, if it has been created in the database. |
Response Code: 200 OK
Response Headers:
content-type: application/json
{
"data": {
"id": "01h909rj94ybjnvpke60w866n6",
"from": "+18332552485",
"to": [
"+16062149989"
],
"text": "Hey Jane! Your verification code is 1234567890.",
"paused": false,
"created_at": "2023-08-29T09:24:58.000000Z",
"sms": [
{
"id": "01h909rjj42mjxcpkxv6asq1jn",
"from": "+18332552485",
"to": "+16062149989",
"text": "Hey Jane! Your verification code is 1234567890.",
"compiled_text": "Hey Jane! Your verification code is 1234567890.",
"status": "sent",
"segment_count": 1,
"error_type": null,
"error_description": null,
"created_at": "2023-08-29T09:24:59.000000Z"
}
],
"sms_activity": [
{
"from": "+18332552485",
"to": "+16062149989",
"created_at": "2023-08-29T09:24:59.000000Z",
"status": "processed",
"sms_message_id": "01h909rj94ybjnvpke60w866n6"
},
{
"from": "+18332552485",
"to": "+16062149989",
"created_at": "2023-08-29T09:24:59.000000Z",
"status": "queued",
"sms_message_id": "01h909rj94ybjnvpke60w866n6"
},
{
"from": "+18332552485",
"to": "+16062149989",
"created_at": "2023-08-29T09:24:59.000000Z",
"status": "sent",
"sms_message_id": "01h909rj94ybjnvpke60w866n6"
}
]
}
}
Error
Response Code: 404 Not Found