Chilkat Online Tools

PowerBuilder / Sunshine Conversations API / List Messages

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_Received
string ls_V_Type
string ls_UserId
string ls_DisplayName
string ls_AvatarUrl
string ls_ContentType
string ls_Text
string ls_SourceType
string ls_IntegrationId
string ls_OriginalMessageId
string ls_OriginalMessageTimestamp
string ls_Id
string ls_ClientType
string ls_Status
string ls_ClientIntegrationId
string ls_ExternalId
string ls_LastSeen
string ls_LinkedAt
string ls_ClientDisplayName
string ls_ClientAvatarUrl
string ls_DeviceId
string ls_DeviceType
string ls_Guid
string ls_ClientId
string ls_DeviceStatus
string ls_DeviceIntegrationId
string ls_DeviceLastSeen
string ls_PushNotificationToken
string ls_AppVersion
string ls_QuotedMessageType
string ls_Value
string ls_Lang
integer li_Deleted
integer j
integer li_Count_j
string ls_Value
integer li_HasMore
string ls_AfterCursor
string ls_BeforeCursor
string ls_Prev
string ls_V_Next
integer i
integer li_Count_i

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "username"
loo_Http.Password = "password"

loo_QueryParams = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat.JsonObject")

loo_QueryParams.UpdateString("page[after]","5e1606762556d93e9c176f69")
loo_QueryParams.UpdateString("page[before]","5e1606762556d93e9c176f69")
loo_QueryParams.UpdateInt("page[size]",10)

loo_Resp = loo_Http.QuickRequestParams("GET","https://domain.com/v2/apps/{{appId}}/conversations/{{conversationId}}/messages",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    return
end if

loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "messages": [
//     {
//       "id": "5e552ef595e5206375bb835d",
//       "received": "2019-03-21T18:48:52.760Z",
//       "author": {
//         "type": "business",
//         "userId": "5963c0d619a30a2e00de36b8",
//         "displayName": "Steve",
//         "avatarUrl": "https://www.gravatar.com/image.jpg"
//       },
//       "content": {
//         "type": "text",
//         "text": "Hello!",
//         "actions": [
//           {
//             "value": "<Error: Too many levels of nesting to fake this schema>"
//           },
//           {
//             "value": "<Error: Too many levels of nesting to fake this schema>"
//           }
//         ]
//       },
//       "source": {
//         "type": "ios",
//         "integrationId": "de13bee15b51033b34162411",
//         "originalMessageId": "5f40256af057d0000dda9bd7",
//         "originalMessageTimestamp": "2019-03-21T18:45:53.720Z",
//         "client": {
//           "id": "5c9a34160c89726709136733",
//           "type": "telegram",
//           "status": "active",
//           "integrationId": "582dedf230e788746891281a",
//           "externalId": "your-own-id",
//           "lastSeen": "2020-08-20T16:13:07.462Z",
//           "linkedAt": "2020-06-23T14:33:47.492Z",
//           "displayName": "Steve",
//           "avatarUrl": "http://EGnaLcOXhxGTLKJ.jpuft043dnis59F",
//           "info": {},
//           "raw": {}
//         },
//         "device": {
//           "id": "de13bee15b51033b34162411",
//           "type": "web",
//           "guid": "in laboris ex",
//           "clientId": "amet minim do eu",
//           "status": "active",
//           "integrationId": "sed enim aliquip commodo",
//           "lastSeen": "elit proident",
//           "pushNotificationToken": "officia labore",
//           "info": {},
//           "appVersion": "irure deserunt qui veniam consequat"
//         }
//       },
//       "quotedMessage": {
//         "type": "message",
//         "message": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       "metadata": {
//         "lang": "en-ca"
//       },
//       "deleted": true
//     },
//     {
//       "id": "5e552ef595e5206375bb835d",
//       "received": "2019-03-21T18:48:52.760Z",
//       "author": {
//         "type": "business",
//         "userId": "5963c0d619a30a2e00de36b8",
//         "displayName": "Steve",
//         "avatarUrl": "https://www.gravatar.com/image.jpg"
//       },
//       "content": {
//         "type": "text",
//         "text": "Hello!",
//         "actions": [
//           {
//             "value": "<Error: Too many levels of nesting to fake this schema>"
//           },
//           {
//             "value": "<Error: Too many levels of nesting to fake this schema>"
//           }
//         ]
//       },
//       "source": {
//         "type": "ios",
//         "integrationId": "de13bee15b51033b34162411",
//         "originalMessageId": "5f40256af057d0000dda9bd7",
//         "originalMessageTimestamp": "2019-03-21T18:45:53.720Z",
//         "client": {
//           "id": "5c9a34160c89726709136733",
//           "type": "telegram",
//           "status": "active",
//           "integrationId": "582dedf230e788746891281a",
//           "externalId": "your-own-id",
//           "lastSeen": "2020-08-20T16:13:07.462Z",
//           "linkedAt": "2020-06-23T14:33:47.492Z",
//           "displayName": "Steve",
//           "avatarUrl": "http://bnAEzvgnDimaLnqEYLUCQXbU.ywrnS-uvD-0kBryUe",
//           "info": {},
//           "raw": {}
//         },
//         "device": {
//           "id": "de13bee15b51033b34162411",
//           "type": "web",
//           "guid": "laborum eiusmod adipisicing esse",
//           "clientId": "labore adipisicing eiusmod",
//           "status": "inactive",
//           "integrationId": "aute",
//           "lastSeen": "anim reprehenderit proident pariatur incididunt",
//           "pushNotificationToken": "qui dolore Excepteur in",
//           "info": {},
//           "appVersion": "incididunt labore dolore pariatur"
//         }
//       },
//       "quotedMessage": {
//         "type": "message",
//         "message": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       "metadata": {
//         "lang": "en-ca"
//       },
//       "deleted": true
//     }
//   ],
//   "meta": {
//     "hasMore": false,
//     "afterCursor": "55c8d9758590aa1900b9b9f6",
//     "beforeCursor": "55c8d9758590aa1900b9b9f6"
//   },
//   "links": {
//     "prev": "https://api.smooch.io/v2/apps?page[before]=fcafad804c39a39648004af9",
//     "next": "https://api.smooch.io/v2/apps?page[after]=5ea868f862cdd24abf010b38"
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

li_HasMore = loo_JResp.BoolOf("meta.hasMore")
ls_AfterCursor = loo_JResp.StringOf("meta.afterCursor")
ls_BeforeCursor = loo_JResp.StringOf("meta.beforeCursor")
ls_Prev = loo_JResp.StringOf("links.prev")
ls_V_Next = loo_JResp.StringOf("links.next")
i = 0
li_Count_i = loo_JResp.SizeOfArray("messages")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Id = loo_JResp.StringOf("messages[i].id")
    ls_Received = loo_JResp.StringOf("messages[i].received")
    ls_V_Type = loo_JResp.StringOf("messages[i].author.type")
    ls_UserId = loo_JResp.StringOf("messages[i].author.userId")
    ls_DisplayName = loo_JResp.StringOf("messages[i].author.displayName")
    ls_AvatarUrl = loo_JResp.StringOf("messages[i].author.avatarUrl")
    ls_ContentType = loo_JResp.StringOf("messages[i].content.type")
    ls_Text = loo_JResp.StringOf("messages[i].content.text")
    ls_SourceType = loo_JResp.StringOf("messages[i].source.type")
    ls_IntegrationId = loo_JResp.StringOf("messages[i].source.integrationId")
    ls_OriginalMessageId = loo_JResp.StringOf("messages[i].source.originalMessageId")
    ls_OriginalMessageTimestamp = loo_JResp.StringOf("messages[i].source.originalMessageTimestamp")
    ls_Id = loo_JResp.StringOf("messages[i].source.client.id")
    ls_ClientType = loo_JResp.StringOf("messages[i].source.client.type")
    ls_Status = loo_JResp.StringOf("messages[i].source.client.status")
    ls_ClientIntegrationId = loo_JResp.StringOf("messages[i].source.client.integrationId")
    ls_ExternalId = loo_JResp.StringOf("messages[i].source.client.externalId")
    ls_LastSeen = loo_JResp.StringOf("messages[i].source.client.lastSeen")
    ls_LinkedAt = loo_JResp.StringOf("messages[i].source.client.linkedAt")
    ls_ClientDisplayName = loo_JResp.StringOf("messages[i].source.client.displayName")
    ls_ClientAvatarUrl = loo_JResp.StringOf("messages[i].source.client.avatarUrl")
    ls_DeviceId = loo_JResp.StringOf("messages[i].source.device.id")
    ls_DeviceType = loo_JResp.StringOf("messages[i].source.device.type")
    ls_Guid = loo_JResp.StringOf("messages[i].source.device.guid")
    ls_ClientId = loo_JResp.StringOf("messages[i].source.device.clientId")
    ls_DeviceStatus = loo_JResp.StringOf("messages[i].source.device.status")
    ls_DeviceIntegrationId = loo_JResp.StringOf("messages[i].source.device.integrationId")
    ls_DeviceLastSeen = loo_JResp.StringOf("messages[i].source.device.lastSeen")
    ls_PushNotificationToken = loo_JResp.StringOf("messages[i].source.device.pushNotificationToken")
    ls_AppVersion = loo_JResp.StringOf("messages[i].source.device.appVersion")
    ls_QuotedMessageType = loo_JResp.StringOf("messages[i].quotedMessage.type")
    ls_Value = loo_JResp.StringOf("messages[i].quotedMessage.message.value")
    ls_Lang = loo_JResp.StringOf("messages[i].metadata.lang")
    li_Deleted = loo_JResp.BoolOf("messages[i].deleted")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("messages[i].content.actions")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Value = loo_JResp.StringOf("messages[i].content.actions[j].value")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -G -d "page[after]=5e1606762556d93e9c176f69"
	-d "page[before]=5e1606762556d93e9c176f69"
	-d "page[size]=10"
	-u 'username:password'
https://domain.com/v2/apps/{{appId}}/conversations/{{conversationId}}/messages

Postman Collection Item JSON

{
  "name": "List Messages",
  "_postman_id": "9f9b265c-7546-4b49-98bf-7e4d85bae5f2",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}/messages?page[after]=5e1606762556d93e9c176f69&page[before]=5e1606762556d93e9c176f69&page[size]=10",
      "host": [
        "{{url}}"
      ],
      "path": [
        "v2",
        "apps",
        "{{appId}}",
        "conversations",
        "{{conversationId}}",
        "messages"
      ],
      "query": [
        {
          "key": "page[after]",
          "value": "5e1606762556d93e9c176f69",
          "description": "Contains parameters for applying cursor pagination."
        },
        {
          "key": "page[before]",
          "value": "5e1606762556d93e9c176f69",
          "description": "Contains parameters for applying cursor pagination."
        },
        {
          "key": "page[size]",
          "value": "10",
          "description": "Contains parameters for applying cursor pagination."
        }
      ]
    },
    "description": "List all messages for a particular conversation. This API is paginated through\n[cursor pagination](#section/Introduction/API-pagination-and-records-limits), in the _backwards_ direction, with the\nmost recent (i.e. last) page of messages being returned by default. The `hasMore` flag indicates whether more messages\nexist in the direction you are currently paginating through. To page backwards in the history, use the `beforeCursor` or follow the `prev`\nlink. The page size limit is fixed at 100 messages per page.\n\n```shell\n/v2/apps/:appId/conversations/:conversationId/messages?page[before]=5f32b88acf6bf25073b2be56\n```\n"
  },
  "response": [
    {
      "id": "550b7411-8e33-4840-8701-23face25cb9a",
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId/messages?page[after]=5e1606762556d93e9c176f69&page[before]=5e1606762556d93e9c176f69&page[size]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId",
            "messages"
          ],
          "query": [
            {
              "key": "page[after]",
              "value": "5e1606762556d93e9c176f69"
            },
            {
              "key": "page[before]",
              "value": "5e1606762556d93e9c176f69"
            },
            {
              "key": "page[size]",
              "value": "10"
            }
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"messages\": [\n  {\n   \"id\": \"5e552ef595e5206375bb835d\",\n   \"received\": \"2019-03-21T18:48:52.760Z\",\n   \"author\": {\n    \"type\": \"business\",\n    \"userId\": \"5963c0d619a30a2e00de36b8\",\n    \"displayName\": \"Steve\",\n    \"avatarUrl\": \"https://www.gravatar.com/image.jpg\"\n   },\n   \"content\": {\n    \"type\": \"text\",\n    \"text\": \"Hello!\",\n    \"actions\": [\n     {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    ]\n   },\n   \"source\": {\n    \"type\": \"ios\",\n    \"integrationId\": \"de13bee15b51033b34162411\",\n    \"originalMessageId\": \"5f40256af057d0000dda9bd7\",\n    \"originalMessageTimestamp\": \"2019-03-21T18:45:53.720Z\",\n    \"client\": {\n     \"id\": \"5c9a34160c89726709136733\",\n     \"type\": \"telegram\",\n     \"status\": \"active\",\n     \"integrationId\": \"582dedf230e788746891281a\",\n     \"externalId\": \"your-own-id\",\n     \"lastSeen\": \"2020-08-20T16:13:07.462Z\",\n     \"linkedAt\": \"2020-06-23T14:33:47.492Z\",\n     \"displayName\": \"Steve\",\n     \"avatarUrl\": \"http://EGnaLcOXhxGTLKJ.jpuft043dnis59F\",\n     \"info\": {},\n     \"raw\": {}\n    },\n    \"device\": {\n     \"id\": \"de13bee15b51033b34162411\",\n     \"type\": \"web\",\n     \"guid\": \"in laboris ex\",\n     \"clientId\": \"amet minim do eu\",\n     \"status\": \"active\",\n     \"integrationId\": \"sed enim aliquip commodo\",\n     \"lastSeen\": \"elit proident\",\n     \"pushNotificationToken\": \"officia labore\",\n     \"info\": {},\n     \"appVersion\": \"irure deserunt qui veniam consequat\"\n    }\n   },\n   \"quotedMessage\": {\n    \"type\": \"message\",\n    \"message\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   \"metadata\": {\n    \"lang\": \"en-ca\"\n   },\n   \"deleted\": true\n  },\n  {\n   \"id\": \"5e552ef595e5206375bb835d\",\n   \"received\": \"2019-03-21T18:48:52.760Z\",\n   \"author\": {\n    \"type\": \"business\",\n    \"userId\": \"5963c0d619a30a2e00de36b8\",\n    \"displayName\": \"Steve\",\n    \"avatarUrl\": \"https://www.gravatar.com/image.jpg\"\n   },\n   \"content\": {\n    \"type\": \"text\",\n    \"text\": \"Hello!\",\n    \"actions\": [\n     {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    ]\n   },\n   \"source\": {\n    \"type\": \"ios\",\n    \"integrationId\": \"de13bee15b51033b34162411\",\n    \"originalMessageId\": \"5f40256af057d0000dda9bd7\",\n    \"originalMessageTimestamp\": \"2019-03-21T18:45:53.720Z\",\n    \"client\": {\n     \"id\": \"5c9a34160c89726709136733\",\n     \"type\": \"telegram\",\n     \"status\": \"active\",\n     \"integrationId\": \"582dedf230e788746891281a\",\n     \"externalId\": \"your-own-id\",\n     \"lastSeen\": \"2020-08-20T16:13:07.462Z\",\n     \"linkedAt\": \"2020-06-23T14:33:47.492Z\",\n     \"displayName\": \"Steve\",\n     \"avatarUrl\": \"http://bnAEzvgnDimaLnqEYLUCQXbU.ywrnS-uvD-0kBryUe\",\n     \"info\": {},\n     \"raw\": {}\n    },\n    \"device\": {\n     \"id\": \"de13bee15b51033b34162411\",\n     \"type\": \"web\",\n     \"guid\": \"laborum eiusmod adipisicing esse\",\n     \"clientId\": \"labore adipisicing eiusmod\",\n     \"status\": \"inactive\",\n     \"integrationId\": \"aute\",\n     \"lastSeen\": \"anim reprehenderit proident pariatur incididunt\",\n     \"pushNotificationToken\": \"qui dolore Excepteur in\",\n     \"info\": {},\n     \"appVersion\": \"incididunt labore dolore pariatur\"\n    }\n   },\n   \"quotedMessage\": {\n    \"type\": \"message\",\n    \"message\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   \"metadata\": {\n    \"lang\": \"en-ca\"\n   },\n   \"deleted\": true\n  }\n ],\n \"meta\": {\n  \"hasMore\": false,\n  \"afterCursor\": \"55c8d9758590aa1900b9b9f6\",\n  \"beforeCursor\": \"55c8d9758590aa1900b9b9f6\"\n },\n \"links\": {\n  \"prev\": \"https://api.smooch.io/v2/apps?page[before]=fcafad804c39a39648004af9\",\n  \"next\": \"https://api.smooch.io/v2/apps?page[after]=5ea868f862cdd24abf010b38\"\n }\n}"
    },
    {
      "id": "b77a129c-bc78-489f-9630-1dbd1d0aa6bd",
      "name": "Message not found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId/messages?page[after]=5e1606762556d93e9c176f69&page[before]=5e1606762556d93e9c176f69&page[size]=10",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId",
            "messages"
          ],
          "query": [
            {
              "key": "page[after]",
              "value": "5e1606762556d93e9c176f69"
            },
            {
              "key": "page[before]",
              "value": "5e1606762556d93e9c176f69"
            },
            {
              "key": "page[size]",
              "value": "10"
            }
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}