Skip to main content

Get SMS Messages

Agent Skill

Automate this endpoint with an AI agent using the 2chat-sms skill:

npx skills add 2ChatCo/agent-skills -s 2chat-sms

Get the SMS thread between one of your SMS channels and a contact phone number. Inbound and outbound messages are merged into a single list, ordered oldest to newest.

Endpoint

GET https://api.p.2chat.io/open/sms/messages/{channel_uuid}/{contact_number}

Authentication

Include your API key in the X-User-API-Key header. Learn more about authentication.

Path parameters

ParameterDescriptionExample
channel_uuidThe UUID of the SMS channel (prefixed SMS)SMS9a3f1c20-4e7b-4d8a-9c61-2f5b8d0a4e13
contact_numberThe contact's phone number in E.164 format+447700900123

Query parameters

ParameterDescriptionExample
results_per_pageNumber of messages to return, between 1 and 200. Default is 5050
before_tsUnix timestamp (seconds). Returns only messages older than this value — use it as a cursor to page back in time1718790043
Paging back in time

The thread is returned oldest to newest. To load older messages, take the timestamp of the earliest message you already have and pass it as before_ts on the next request.

Invocation

curl -L -G 'https://api.p.2chat.io/open/sms/messages/SMS9a3f1c20-4e7b-4d8a-9c61-2f5b8d0a4e13/+447700900123?results_per_page=50' \
--header 'X-User-API-Key: your_api_key_here'

Response

Each message is tagged with a direction (inbound or outbound) and a unix timestamp. Inbound and outbound messages carry slightly different fields.

Success (HTTP 200 OK)

{
"success": true,
"count": 2,
"messages": [
{
"uuid": "SMI4f2a1c33-7b6e-4d9a-8c12-9f0e1a2b3c4d",
"destination": "+13057654321",
"source": "+447700900123",
"text": "Hi, is my order ready?",
"direction": "inbound",
"price": 0.0,
"voip_number_setup_id": 42,
"created_at": "2026-06-20T10:58:02Z",
"updated_at": "2026-06-20T10:58:02Z",
"timestamp": 1718883482
},
{
"uuid": "SMOe8b1d572-6a4c-4f93-8d20-1c7b5e0a9f64",
"destination": "+447700900123",
"source": "+13057654321",
"text": "Yes! It ships today.",
"fragments": 1,
"direction": "outbound",
"price": 0.0075,
"voip_number_setup_id": 42,
"created_at": "2026-06-20T11:01:30Z",
"updated_at": "2026-06-20T11:01:30Z",
"timestamp": 1718883690
}
]
}
FieldDescription
successtrue when the request was successful
countNumber of messages returned in this response
messagesArray of message objects, oldest to newest (see below)

Each message object contains:

FieldDescriptionExample
uuidUnique identifier of the message. Inbound is prefixed SMI, outbound SMOSMI4f2a1c33-7b6e-4d9a-8c12-9f0e1a2b3c4d
destinationRecipient phone number in E.164 format+13057654321
sourceSender phone number in E.164 format+447700900123
textThe message contentHi, is my order ready?
directioninbound (received) or outbound (sent)inbound
fragmentsNumber of SMS segments (outbound messages only)1
priceThe amount billed to you for the message, in USD0.0075
voip_number_setup_idInternal identifier of the underlying virtual number setup42
created_atWhen the message was created (UTC)2026-06-20T10:58:02Z
updated_atWhen the message was last updated (UTC)2026-06-20T10:58:02Z
timestampUnix timestamp (seconds) of the message1718883482

Error

{
"error": true,
"error_message": "Description of what went wrong"
}
FieldDescription
errortrue when the request failed
error_messageA description of what went wrong

A channel that doesn't exist or doesn't belong to your account returns 404 Not Found.