Conversations
The inbox has one thread per contact. To reply, send to the contact with POST /v1/messages; it lands in the same thread. View-only teammates can read conversations but not change them. Reading a thread still marks it read (see List a thread’s messages). An id that isn’t on your account returns 404 CONVERSATION_NOT_FOUND. An id that isn’t a whole number returns 400 invalid_field.
#The Conversation object
List conversations returns this object. Find a contact’s conversation returns a shorter row (see there). Ignore fields you don’t recognize.
idinteger- The conversation id.
contact_idinteger- The contact id.
first_namestring- The contact’s first name.
last_namestring- The contact’s last name.
phoneE.164 string- The contact’s phone.
statusstringopen,closedorarchived.nullandactivemean open: treat them the same. Set it with Set a conversation’s status.unread_countinteger- Unread messages in the thread. Mark read and Archive clear it; Mark unread sets it to
1. starredinteger1or0. Toggle it with Star or unstar a conversation.pinnedinteger1or0.assigned_tointeger | null- Who the thread is assigned to, or
null. This is the contact’s owner when the contact has one, else the thread’s own assignee. Set it with Assign a conversation. last_message_atISO 8601 string- When the newest message was sent or received. The list is sorted by it, newest first.
last_message_previewstring- The start of the most recent message.
phone_number_idinteger- The id of your number the thread uses, as in
GET /v1/numbersandline_ids. from_numberE.164 string- Your number the thread uses.
tagsstring- The contact’s tags as a JSON array in a string, like
"[\"vip\"]". Parse it before you use it. contact_statusstring | null- The contact’s status.
dnd_smsinteger | null1when the contact is on do not disturb for texts.opt_out_atISO 8601 string | null- When the contact opted out, or
null.
#List conversations
Your inbox threads, newest message first. Starring doesn’t change the order; use filter=starred. Returns a list of Conversation objects in data.
Parameters
limitinteger, queryDefault50Max1000- Page size.
offsetinteger, queryDefault0- Rows to skip: a whole number, 0 or more.
filterenum, query- Which view; default is every thread that isn’t archived, closed ones included. Unknown values are ignored.
unreadstarredarchivedspamblocked
searchstring, query- Matches the contact’s name, phone, email or company, or the first 100 characters of the thread’s most recent message. Older messages aren’t searched. A full phone number in any format matches exactly.
line_idsstring, query- Comma-separated number ids from
GET /v1/numbers(not phone numbers), up to 100, for exampleline_ids=2647,2648. Invalid values are ignored. When none of them is a number id the whole inbox comes back, and the answer hasignored_filters: ["line_ids"]to say the filter was dropped. freshinteger, query- Lists are cached up to 30 seconds, and longer when the server is slow to refresh them. Send
1after a change to read live.
Returns
data[]object[]- Conversation objects.
has_moreboolean- Keep paging while
true. search_timed_outbooleantruewhen a search ran out of time. Ifdatais empty, that is not "no matches": narrow the search and retry.search_partialbooleantruemeans some matches may be missing.totalinteger- Threads matching
filterandsearch, counted up to 1,000. While searching, or filtering by tag, assignee or campaign,totalis the rows returned so far, not a count, so usehas_more. Withline_ids,totalandcountscover only those numbers. total_cappedbooleantruewhen the count passed the cap.count_capinteger- The cap,
1000. countsobject- Thread counts per view:
all(the default view, without archived),unread,starred,pinned,archived,spam.
Errors
| HTTP | Code | When |
|---|---|---|
| 400 | invalid_offset | Not a whole number, 0 or more (in error_code). |
#List messages in a conversation
One thread’s messages: the newest page, oldest first within the page. Returns a list of Message objects in data, with the differences under Returns.
mark_read=0. A test key never marks a thread read.Parameters
idinteger, pathRequired- The conversation id.
mark_readinteger, query- Send
0to leave the unread state alone. limitinteger, queryDefault50Max500- Page size.
offsetinteger, queryDefault0- Increase to go further back in time.
Returns
data[].idinteger- This thread’s message id, the one
quoted_message_idtakes on Send a message. data[].to_numberE.164 string- Recipient.
data[].from_numberE.164 string- Sender.
data[].costnumber- What the message cost, in USD.
data[].failed_atISO 8601 string | null- When it failed, or
null.
Errors
| HTTP | Code | When |
|---|---|---|
| 403 | CONVERSATION_NOT_ASSIGNED | Teammate access doesn’t cover this thread: it’s assigned to someone else. Also CONVERSATION_NOT_ALLOCATED: the thread’s number isn’t allocated to you. |
#Find a contact’s conversation
The thread for one contact, or null if there isn’t one. An unknown contact id also returns null, not a 404.
Parameters
contactIdinteger, pathRequired- The contact id.
Returns
dataobject | null- A shorter Conversation object, or
null. It has notags. Itsassigned_tois the thread’s own assignee, andcontact_assigned_tois the contact’s owner, so it can differ from the list’sassigned_to.
Errors
| HTTP | Code | When |
|---|---|---|
| 403 | CONVERSATION_NOT_ASSIGNED | Teammate access doesn’t cover this thread: it’s assigned to someone else. Also CONVERSATION_NOT_ALLOCATED: the thread’s number isn’t allocated to you. |
#Best time to text a contact
A 2-hour window when this contact has replied to you most, from the hours of their past replies. It needs at least 3 replies; with fewer you get best: null. The window always falls between 9 AM and 7 PM in your account’s time zone. Read only.
Parameters
contactIdinteger, pathRequired- The contact id.
Returns
bestobject | null- The window, at the top level, or
nullwhen there aren’t enough replies. best.start_hhmmstring- Start of the window, like
14:00. best.end_hhmmstring- End of the window, 2 hours later.
best.labelstring- The window in words, like
2 PM to 4 PM. best.sampleinteger- How many replies it’s based on.
best.sourcestring- Always
contact. best.reasonstring- A short sentence you can show.
timezonestring- Your account’s IANA time zone. The window’s hours are in this zone.
Errors
| HTTP | Code | When |
|---|---|---|
| 400 | INVALID_CONTACT_ID | Not a contact id (for example a phone number). |
| 403 | CONVERSATION_NOT_ASSIGNED | Teammate access doesn’t cover this thread: it’s assigned to someone else. Also CONVERSATION_NOT_ALLOCATED: the thread’s number isn’t allocated to you. |
| 500 | best_time_unavailable | We couldn’t work it out right now. This is a failure, not "no data"; retry. |
See also: the guide to doing this in the app.