Retrieving Message Logs
Retrieve individual messages or paginated logs, understand message timestamps, and collect records for reporting.
Retrieve messages
Use these endpoints:
- Retrieve Message to retrieve a message using its SID.
- Retrieve All Messages to retrieve a filtered, paginated message list.
Use the intended account’s SID in the URL. To collect logs across multiple subaccounts, retrieve each subaccount’s records separately.
Filter the message list
The list endpoint supports:
| Parameter | Purpose |
|---|---|
To | Filter by recipient phone number. |
From | Filter by sending phone number. |
DateSent | Filter by a specific date. |
DateSent> | Supply a lower date boundary. |
DateSent< | Supply an upper date boundary. |
Page | Select a zero-based page. Defaults to 0. |
PageSize | Set the requested page size. Defaults to 50. |
Use yyyy-MM-dd for date values. Use either a specific-date filter or range boundaries rather than combining both.
URL-encode query parameters, especially phone numbers containing + and parameter names containing < or >.
For example:
curl --get "https://api.textgrid.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID/Messages.json" \
--user "YOUR_ACCOUNT_SID:YOUR_AUTH_TOKEN" \
--data-urlencode "DateSent=2026-11-09" \
--data-urlencode "Page=0" \
--data-urlencode "PageSize=50"curl --get "https://api.textgrid.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID/Messages.json" \
-H "Authorization: Bearer YOUR_BASE64_ENCODED_CREDENTIALS" \
--data-urlencode "DateSent=2026-11-09" \
--data-urlencode "Page=0" \
--data-urlencode "PageSize=50"Understand message timestamps
Message dates returned by these endpoints use the account’s configured time zone. Date filters are also interpreted using that account’s time zone.
JSON timestamps use a format such as:
Mon, 09 Nov 2026 14:30:00 +0000The +0000 suffix does not mean these account-local message timestamps are UTC. Interpret the time using the account’s configured time zone rather than relying on that suffix.
Do not assume date_updated is a reliable timestamp for the latest delivery-status change. Use delivery callbacks and refresh message records when you need current status.
Retrieve every page
The response contains a messages array and pagination information, including next_page_uri.
Start at page 0, process the returned records, and continue until next_page_uri is absent or null.
Pagination URLs can be relative paths. Resolve them against:
https://api.textgrid.comKeep the same account and filters throughout the export. An active result set can change while you are paging through it, so save records by message SID rather than treating every returned row as new.
Collect logs daily
For a daily reporting workflow:
- Select the date using the account’s configured time zone.
- Retrieve every page for that date.
- Save or update records using the message SID as the unique key.
- Mark the collection complete only after all pages succeed.
- Revisit recent dates to capture later delivery updates.
If a run fails, retry the affected date and update existing records rather than inserting duplicates.
A daily collection is not a final delivery snapshot. Messages can remain queued or pending, and their results can change after the initial collection.
Use Messaging Webhooks for delivery updates and periodically reconcile them with retrieved records.
Interpret message results
Read the message’s current status. Retrieved records can include a description alongside the state, such as:
failed - 'To' number invalidDo not require error_code or error_message to be present before recognizing a failure.
See Delivery Status Reference for statuses and descriptions.
Handle retrieval errors
If a request fails, check the HTTP response before treating it as an empty message list.
If you receive HTTP 409 with Please wait for existing API call to finish, allow the outstanding request to complete before retrying.
Avoid launching overlapping exports for the same account and date range. If an error persists, contact support with the account SID, requested date range, approximate request time, and HTTP status. Do not include your Auth Token.
Protect message records
Message logs can contain phone numbers, message content, and media links. Restrict access to exported records and retain only what your application needs.
Updated 14 days ago