List all messages
Use this endpoint for the Media method to return a paged list of messages sorted with the most recent messages appearing first.
Parameters
Parameter | Description |
---|---|
DateSent Optional | Only return messages sent on this particular date, formatted as YYYY-MM-DD in UTC. You can also append < or > to return a range of messages. For example, use DateSent< to return messages sent on or before midnight of the date, or DateSent> to return messages sent on or after midnight of the date. |
From Optional | Only return messages sent from this phone number. |
To Optional | Only return messages sent to this phone number. |
Status Optional | Only return messages that currently have the specified status. |
PageSize Optional | Specify the number of results to return on a single page. The default page size is 50 and the maximum is 1000. |
Examples
Request: List All Messages
In this example, we will list all Messages.
- cURL
- Node.js
- C#
- Python
- Ruby
curl https://example.signalwire.com/api/laml/2010-04-01/Accounts/{AccountSid}/Messages.json \
-X GET \
-u "YourProjectID:YourAuthToken"
const { RestClient } = require('@signalwire/compatibility-api')
const client = RestClient('YourProjectID', 'YourAuthToken', { signalwireSpaceUrl: 'example.signalwire.com' })
client.messages.each(messages => console.log(messages.sid));
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
TwilioClient.Init("YourProjectID", "YourAuthToken", new Dictionary<string, object> { ["signalwireSpaceUrl"] = "{SPACE}.signalwire.com" });
var messages = MessageResource.Read();
foreach(var record in messages)
{
Console.WriteLine(record.Sid);
}
}
}
from signalwire.rest import Client as signalwire_client
client = signalwire_client("YourProjectID", "YourAuthToken", signalwire_space_url = 'example.signalwire.com')
messages = client.messages.list()
for record in messages:
print(record.sid)
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'YourProjectID', 'YourAuthToken', signalwire_space_url: "example.signalwire.com"
messages = @client.messages.list
messages.each do |record|
puts record.sid
end
Responses
200 OK
{
"uri": "/api/laml/2010-04-01/Accounts/ea108133-d6b3-407c-9536-9fad8a929a6a/Messages?Page=0&PageSize=50",
"first_page_uri": "/api/laml/2010-04-01/Accounts/ea108133-d6b3-407c-9536-9fad8a929a6a/Messages?Page=0&PageSize=50",
"next_page_uri": null,
"previous_page_uri": null,
"page": 0,
"page_size": 50,
"messages": [
{
"account_sid": "ea108133-d6b3-407c-9536-9fad8a929a6a",
"api_version": "2010-04-01",
"body": "Hello World",
"num_segments": 1,
"num_media": 0,
"date_created": "Mon, 13 Aug 2018 23:08:35 +0000",
"date_sent": "Mon, 13 Aug 2018 23:08:40 +0000",
"date_updated": "Mon, 13 Aug 2018 23:08:40 +0000",
"direction": "outbound-api",
"error_code": null,
"error_message": null,
"from": "+15551234567",
"price": 0.005,
"price_unit": "USD",
"sid": "b3877c40-da60-4998-90ad-b792e98472af",
"status": "delivered",
"to": "+15557654321",
"messaging_service_sid": null,
"uri": "/api/laml/2010-04-01/Accounts/ea108133-d6b3-407c-9536-9fad8a929a6a/Messages/b3877c40-da60-4998-90ad-b792e98472af",
"subresource_uris": {
"media": "/api/laml/2010-04-01/Accounts/ea108133-d6b3-407c-9536-9fad8a929a6a/Messages/b3877c40-da60-4998-90ad-b792e98472af/Media"
}
}
]
}
Request: Filter By Date and From
In this example, we will filter messages to return only those sent from +15551234567
on or after 2018-08-01
.
- cURL
- Node.js
- C#
- Python
- Ruby
curl https://example.signalwire.com/api/laml/2010-04-01/Accounts/{AccountSid}/Messages.json?From=%2b15551234567&DateSent>=2018-08-01 \
-X GET \
-u "YourProjectID:YourAuthToken"
const { RestClient } = require('@signalwire/compatibility-api')
const client = RestClient('YourProjectID', 'YourAuthToken', { signalwireSpaceUrl: 'example.signalwire.com' })
client.messages.each({ dateSent: new Date(Date.UTC(2018, 8, 1, 0, 0, 0)), from: '+15551234567' },
messages => console.log(messages.sid)
);
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
TwilioClient.Init("YourProjectID", "YourAuthToken", new Dictionary<string, object> { ["signalwireSpaceUrl"] = "{SPACE}.signalwire.com" });
var messages = MessageResource.Read(
dateSent: new DateTime(2018, 8, 1, 0, 0, 0),
from: new Twilio.Types.PhoneNumber("+15551234567")
);
foreach(var record in messages)
{
Console.WriteLine(record.Sid);
}
}
}
from signalwire.rest import Client as signalwire_client
client = signalwire_client("YourProjectID", "YourAuthToken", signalwire_space_url = 'example.signalwire.com')
messages = client.messages.list(
date_sent=datetime(2018, 8, 1, 0, 0),
from_='+15551234567'
)
for record in messages:
print(record.sid)
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'YourProjectID', 'YourAuthToken', signalwire_space_url: "example.signalwire.com"
messages = @client.messages.list(
date_sent: Date.new(2018, 8, 1),
from: '+15551234567'
)
messages.each do |record|
puts record.sid
end