threadId in Inbox and messages API

Hi, @TraceTheStar :waving_hand: This one is a bit of an adventure for sure. Fortunately, everything we need is in the Conversations inbox and messages APIs (BETA).

Our clue was down the page a bit “When you make a successful request, the response will include the thread ID, which you can use to retrieve, update, or create a new message in a thread.” Retrieve threads.

My quick test is likely different than you, but I think the underlying approach will get what you are after.

Request 1 — Get threadId

GET /conversations/v3/conversations/threads

The response includes a property called id which is actually the threadId in this case

My request

curl --request GET \
 --url https://api.hubapi.com/conversations/v3/conversations/threads \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN'

My response

HTTP 200

{
 "results": [
 {
 "id": "3016120935",
 "createdAt": "2022-08-11T23:26:58.904Z",
 "status": "OPEN",
 "latestMessageTimestamp": "2022-08-11T23:28:36.188Z",
 "latestMessageSentTimestamp": "2022-08-11T23:28:36.188Z",
 "latestMessageReceivedTimestamp": "2022-08-11T23:26:58.969Z",
 "assignedTo": "A-10233975",
 "spam": false,
 "inboxId": "124212669",
 "associatedContactId": "551",
 "archived": false
 },
 {
 "id": "3016291208",
 "createdAt": "2022-08-11T23:23:48.172Z",
 "status": "OPEN",
 "latestMessageTimestamp": "2022-08-11T23:23:54.489Z",
 "latestMessageReceivedTimestamp": "2022-08-11T23:23:54.489Z",
 "spam": false,
 "inboxId": "124212669",
 "associatedContactId": "1",
 "archived": false
 },
 {
 "id": "3016313742",
 "createdAt": "2022-08-11T23:24:36.472Z",
 "closedAt": "2022-08-11T23:25:46.568Z",
 "status": "CLOSED",
 "latestMessageTimestamp": "2022-08-11T23:24:36.689Z",
 "latestMessageReceivedTimestamp": "2022-08-11T23:24:36.689Z",
 "assignedTo": "A-10233975",
 "spam": false,
 "inboxId": "124212669",
 "associatedContactId": "1",
 "archived": false
 }
 ],
 "paging": {
 "next": {
 "after": "MzAxNjMxMzc0Mg%3D%3D",
 "link": "https://api.hubapi.com/conversations/v3/conversations/threads?hs_static_app=endpoint-reference-ui&hs_static_app_version=1.974&after=MzAxNjMxMzc0Mg%3D%3D"
 }
 }
}

Request 2 — Get messageId

We can take the value for “id”: “3016120935” and get the associated messages from this endpoint:

GET /conversations/v3/conversations/threads/{threadId}/messages

My request

curl --request GET \
 --url https://api.hubapi.com/conversations/v3/conversations/threads/3016120935/messages \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN'

My response

HTTP 200

{
 "results": [
 {
 "id": "d3295feca7814dc0806ae1c96636d705",
 "createdAt": "2022-08-11T23:28:36.188Z",
 "updatedAt": "2022-08-11T23:28:36.188Z",
 "createdBy": "A-10233975",
 "client": {
 "clientType": "HUBSPOT"
 },
 "senders": [
 {
 "actorId": "A-10233975"
 }
 ],
 "recipients": [
 {
 "actorId": "V-551",
 "deliveryIdentifiers": []
 }
 ],
 "channelId": "1000",
 "channelAccountId": "79569651",
 "archived": false,
 "text": "this is a test",
 "richText": "<div style=\"text-align: left\">this is a test</div>",
 "attachments": [],
 "truncationStatus": "NOT_TRUNCATED",
 "status": {
 "statusType": "SENT"
 },
 "direction": "OUTGOING",
 "type": "MESSAGE"
 },
 {
 "id": "56b8f95f373149afa3cffaf6dddf1825",
 "createdAt": "2022-08-11T23:28:10.344Z",
 "updatedAt": "2022-08-11T23:28:10.344Z",
 "createdBy": "A-10233975",
 "client": {
 "clientType": "HUBSPOT"
 },
 "senders": [
 {
 "actorId": "A-10233975"
 }
 ],
 "recipients": [
 {
 "actorId": "V-551",
 "deliveryIdentifiers": []
 }
 ],
 "channelId": "1000",
 "channelAccountId": "79569651",
 "archived": false,
 "text": "hello",
 "richText": "<div style=\"text-align: left\">hello</div>",
 "attachments": [],
 "truncationStatus": "NOT_TRUNCATED",
 "status": {
 "statusType": "SENT"
 },
 "direction": "OUTGOING",
 "type": "MESSAGE"
 },
 {
 "id": "4a41191f2a0d406ebb208e06f42559b3",
 "createdAt": "2022-08-11T23:27:57.101Z",
 "updatedAt": "2022-08-11T23:27:57.101Z",
 "createdBy": "A-10233975",
 "client": {
 "clientType": "HUBSPOT"
 },
 "senders": [
 {
 "actorId": "A-10233975"
 }
 ],
 "recipients": [
 {
 "actorId": "V-551",
 "deliveryIdentifiers": []
 }
 ],
 "channelId": "1000",
 "channelAccountId": "79569651",
 "archived": false,
 "text": "hellp",
 "richText": "<div style=\"text-align: left\">hellp</div>",
 "attachments": [],
 "truncationStatus": "NOT_TRUNCATED",
 "status": {
 "statusType": "SENT"
 },
 "direction": "OUTGOING",
 "type": "MESSAGE"
 },
 {
 "id": "75dd0ade-60ca-4952-a49b-fc8fa94f7f92",
 "createdAt": "2022-08-11T23:26:59.661Z",
 "createdBy": "S-hubspot",
 "client": {
 "clientType": "SYSTEM"
 },
 "senders": [],
 "recipients": [],
 "archived": false,
 "assignedTo": "A-10233975",
 "type": "ASSIGNMENT"
 },
 {
 "id": "1c83f851-4814-4ce5-93b2-ef17b54ac339",
 "createdAt": "2022-08-11T23:26:59.621Z",
 "createdBy": "S-hubspot",
 "client": {
 "clientType": "SYSTEM"
 },
 "senders": [],
 "recipients": [],
 "archived": false,
 "newStatus": "OPEN",
 "type": "THREAD_STATUS_CHANGE"
 },
 {
 "id": "7c5bbeb0801f455c95b3e6fd85cc7d3d",
 "createdAt": "2022-08-11T23:26:58.969Z",
 "updatedAt": "2022-08-11T23:26:58.969Z",
 "createdBy": "V-551",
 "client": {
 "clientType": "SYSTEM"
 },
 "senders": [
 {
 "actorId": "V-551"
 }
 ],
 "recipients": [],
 "channelId": "1000",
 "channelAccountId": "79569651",
 "archived": false,
 "text": "Hello",
 "richText": "<div>Hello</div>",
 "attachments": [],
 "truncationStatus": "NOT_TRUNCATED",
 "status": {
 "statusType": "RECEIVED"
 },
 "direction": "INCOMING",
 "type": "MESSAGE"
 },
 {
 "id": "e5a4bc4685d74194becd81f8fdc03748",
 "createdAt": "2022-08-11T23:26:58.967Z",
 "createdBy": "S-hubspot",
 "client": {
 "clientType": "SYSTEM"
 },
 "senders": [
 {
 "actorId": "S-hubspot"
 }
 ],
 "recipients": [
 {
 "actorId": "V-551",
 "deliveryIdentifiers": []
 }
 ],
 "channelId": "1000",
 "channelAccountId": "79569651",
 "archived": false,
 "text": "Got any questions? I'm happy to help.",
 "type": "WELCOME_MESSAGE"
 }
 ],
 "paging": {
 "next": {
 "after": "MTY2MDI2MDQxODk2Ny0w",
 "link": "https://api.hubapi.com/conversations/v3/conversations/threads/3016120935/messages?hs_static_app=endpoint-reference-ui&hs_static_app_version=1.974&after=MTY2MDI2MDQxODk2Ny0w"
 }
 }
}

Essentially, you’ll need one call to get the threadIds and a second to get the messageIds. With that information, you can follow the documentation to retrieve messages.

Have fun coding! – Jaycee