Chilkat Online Tools

PureBasic / Zoom API / List user's chat messages

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkDtObj.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"to_contact","quis officia in reprehenderit")
    CkJsonObject::ckUpdateString(queryParams,"to_channel","quis officia in reprehenderit")
    CkJsonObject::ckUpdateString(queryParams,"date","1989-05-07")
    CkJsonObject::ckUpdateInt(queryParams,"page_size",10)
    CkJsonObject::ckUpdateString(queryParams,"next_page_token","quis officia in reprehenderit")
    CkJsonObject::ckUpdateString(queryParams,"include_deleted_and_edited_message","quis officia in reprehenderit")
    CkJsonObject::ckUpdateString(queryParams,"search_type","message")
    CkJsonObject::ckUpdateString(queryParams,"search_key","quis nisi Duis ut")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://api.zoom.us/v2/chat/users/:userId/messages",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

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

    ; {
    ;   "date": "2019-09-17",
    ;   "page_size": 10,
    ;   "next_page_token": "",
    ;   "messages": [
    ;     {
    ;       "id": "F3CbafdljsfjkdfgBA7",
    ;       "message": "And you?",
    ;       "sender": "user@example.com",
    ;       "date_time": "2019-09-17T20:25:21Z",
    ;       "timestamp": 1568751921626
    ;     },
    ;     {
    ;       "id": "B0DbfdgdfhAAfgf237000",
    ;       "message": "I am good",
    ;       "sender": "user@example.com",
    ;       "date_time": "2019-09-17T20:25:17Z",
    ;       "timestamp": 1568751917976
    ;     },
    ;     {
    ;       "id": "C9Bbdfgd4sad301",
    ;       "message": "How are you",
    ;       "sender": "user@example.com",
    ;       "date_time": "2019-09-17T20:24:13Z",
    ;       "timestamp": 1568751853297
    ;     },
    ;     {
    ;       "id": "{3136F1FB-0B0C-410B-B316-E969FAA17A31}",
    ;       "message": "example_user has sent you an image",
    ;       "sender": "example_user@example.com",
    ;       "date_time": "2021-11-19T10:12:35Z",
    ;       "timestamp": 1637316755220,
    ;       "file_id": "-5x5lHOiT2Kc41ZfItJAAw",
    ;       "file_name": "screenshot at 181229.png",
    ;       "file_size": 82377,
    ;       "download_url": "https://example.com/file/download/-5x5lHOiT2Kc41ZfItJAAw?jwt=eyJhbGciOiJIUzI1NiJ9.eyJkaWciOiI5ZDE3NWFjMzkyM&mode=download"
    ;     },
    ;     {
    ;       "sender": "example_user@example.com",
    ;       "date_time": "2021-11-19T10:12:35Z",
    ;       "timestamp": 1637316755220,
    ;       "file_id": "-5x5lHOiT2Kc41ZfItJAAw",
    ;       "file_name": "example.png",
    ;       "file_size": 82377,
    ;       "download_url": "https://example.com/file/download/-5x5lHOiT2Kc41ZfItJAAw?jwt=eyJhbGciOiJIUzI1NiJ9.eyJkaWciOiI5ZDE3NWFjMz&mode=download"
    ;     }
    ;   ]
    ; }

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

    date_time.i = CkDtObj::ckCreate()
    If date_time.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    id.s
    message.s
    sender.s
    timestamp.i
    file_id.s
    file_name.s
    file_size.i
    download_url.s

    date.s = CkJsonObject::ckStringOf(jResp,"date")
    page_size.i = CkJsonObject::ckIntOf(jResp,"page_size")
    next_page_token.s = CkJsonObject::ckStringOf(jResp,"next_page_token")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"messages")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckStringOf(jResp,"messages[i].id")
        message = CkJsonObject::ckStringOf(jResp,"messages[i].message")
        sender = CkJsonObject::ckStringOf(jResp,"messages[i].sender")
        CkJsonObject::ckDtOf(jResp,"messages[i].date_time",0,date_time)
        timestamp = CkJsonObject::ckIntOf(jResp,"messages[i].timestamp")
        file_id = CkJsonObject::ckStringOf(jResp,"messages[i].file_id")
        file_name = CkJsonObject::ckStringOf(jResp,"messages[i].file_name")
        file_size = CkJsonObject::ckIntOf(jResp,"messages[i].file_size")
        download_url = CkJsonObject::ckStringOf(jResp,"messages[i].download_url")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)
    CkDtObj::ckDispose(date_time)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "to_contact=quis%20officia%20in%20reprehenderit"
	-d "to_channel=quis%20officia%20in%20reprehenderit"
	-d "date=1989-05-07"
	-d "page_size=10"
	-d "next_page_token=quis%20officia%20in%20reprehenderit"
	-d "include_deleted_and_edited_message=quis%20officia%20in%20reprehenderit"
	-d "search_type=message"
	-d "search_key=quis%20nisi%20Duis%20ut"
	-H "Authorization: Bearer <access_token>"
https://api.zoom.us/v2/chat/users/:userId/messages

Postman Collection Item JSON

{
  "name": "List user's chat messages",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/chat/users/:userId/messages?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit&date=1989-05-07&page_size=10&next_page_token=quis officia in reprehenderit&include_deleted_and_edited_message=quis officia in reprehenderit&search_type=message&search_key=quis nisi Duis ut",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "chat",
        "users",
        ":userId",
        "messages"
      ],
      "query": [
        {
          "key": "to_contact",
          "value": "quis officia in reprehenderit",
          "description": "Query by the email address of a chat contact with whom the user communicated. The API only returns messages sent and/or received between the user and the queried contact. \n\n**Note:** \n* You must provide either the `to_contact` or the `to_channel` query parameter. \n* When you call the `search_key` and `search_type` query parameters, this query parameter is optional and **not** required."
        },
        {
          "key": "to_channel",
          "value": "quis officia in reprehenderit",
          "description": "Query by the channel ID of a channel in which the user had chat conversations. The API only returns messages sent and/or received by the user in the queried channel. \n\n**Note:** \n* You must provide either the `to_contact` or the `to_channel` query parameter. \n* When you call the `search_key` and `search_type` query parameters, this query parameter is optional and **not** required."
        },
        {
          "key": "date",
          "value": "1989-05-07",
          "description": "The query date for which you would like to get the chat messages. This value defaults to the current date."
        },
        {
          "key": "page_size",
          "value": "10",
          "description": "The number of records returned with a single API call. "
        },
        {
          "key": "next_page_token",
          "value": "quis officia in reprehenderit",
          "description": "The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes."
        },
        {
          "key": "include_deleted_and_edited_message",
          "value": "quis officia in reprehenderit",
          "description": "**Optional** <br>\nSet the value of this field to `true` to include edited and deleted messages in the response."
        },
        {
          "key": "search_type",
          "value": "message",
          "description": "The type of search: \n* `message` — Search messages. \n* `file` — Search files. \n\n**Note:** \n* If you use this query parameter, you must also include a `search_key` query parameter value. \n* The `to_contact` and the `to_channel` query parameters are **not** required when you query this parameter. If you do not call them, the API returns **all** contact and channel messages that match the `search_type` query. \n* If you query this parameter, you **cannot** also query the `include_deleted_and_edited_message` parameter. This query parameter does not support the return of deleted or updated messages."
        },
        {
          "key": "search_key",
          "value": "quis nisi Duis ut",
          "description": "The messages or files query string, up to 256 characters. \n\n**Note:** \n* If you use this query parameter, you must also include a `search_type` query parameter value. \n* The `to_contact` and the `to_channel` query parameters are **not** required when you query this parameter. If you do not call them, the API returns **all** contact and channel messages that match the `search_key` query. \n* If you query this parameter, you **cannot** also query the `include_deleted_and_edited_message` parameter. This query parameter does not support the return of deleted or updated messages."
        }
      ],
      "variable": [
        {
          "key": "userId"
        }
      ]
    },
    "description": "Use this API to search chat messages and/or shared files between a user and an individual contact or a chat channel. For user-level apps, pass [the `me` value](https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#mekeyword) instead of the `userId` parameter. \n\n <p style=\"background-color:#e1f5fe; color:#01579b; padding:8px\"> <b>Note:</b> For an <b>account-level</b> <a href=\"https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app\">OAuth app</a>, this API can only be used on behalf of a user who is assigned with a <a href=\"https://support.zoom.us/hc/en-us/articles/115001078646-Using-role-management#:~:text=Each%20user%20in%20a%20Zoom,owner%2C%20administrator%2C%20or%20member.&text=Role%2Dbased%20access%20control%20enables,needs%20to%20view%20or%20edit.\">role</a> that has the <b>View</b> or <b>Edit</b> permission for <b>Chat Messages</b>.</p> \n\n**Scopes:** `chat_message:read`, `chat_message:read:admin` <br> **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`"
  },
  "response": [
    {
      "name": "**HTTP Status Code:**`200`<br>\nList of chat messages returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit&date=1989-05-07&page_size=10&next_page_token=quis officia in reprehenderit&include_deleted_and_edited_message=quis officia in reprehenderit&search_type=message&search_key=quis nisi Duis ut",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages"
          ],
          "query": [
            {
              "key": "to_contact",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "to_channel",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "date",
              "value": "1989-05-07"
            },
            {
              "key": "page_size",
              "value": "10"
            },
            {
              "key": "next_page_token",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "include_deleted_and_edited_message",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "search_type",
              "value": "message"
            },
            {
              "key": "search_key",
              "value": "quis nisi Duis ut"
            }
          ],
          "variable": [
            {
              "key": "userId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"date\": \"2019-09-17\",\n \"page_size\": 10,\n \"next_page_token\": \"\",\n \"messages\": [\n  {\n   \"id\": \"F3CbafdljsfjkdfgBA7\",\n   \"message\": \"And you?\",\n   \"sender\": \"user@example.com\",\n   \"date_time\": \"2019-09-17T20:25:21Z\",\n   \"timestamp\": 1568751921626\n  },\n  {\n   \"id\": \"B0DbfdgdfhAAfgf237000\",\n   \"message\": \"I am good\",\n   \"sender\": \"user@example.com\",\n   \"date_time\": \"2019-09-17T20:25:17Z\",\n   \"timestamp\": 1568751917976\n  },\n  {\n   \"id\": \"C9Bbdfgd4sad301\",\n   \"message\": \"How are you\",\n   \"sender\": \"user@example.com\",\n   \"date_time\": \"2019-09-17T20:24:13Z\",\n   \"timestamp\": 1568751853297\n  },\n  {\n   \"id\": \"{3136F1FB-0B0C-410B-B316-E969FAA17A31}\",\n   \"message\": \"example_user has sent you an image\",\n   \"sender\": \"example_user@example.com\",\n   \"date_time\": \"2021-11-19T10:12:35Z\",\n   \"timestamp\": 1637316755220,\n   \"file_id\": \"-5x5lHOiT2Kc41ZfItJAAw\",\n   \"file_name\": \"screenshot at 181229.png\",\n   \"file_size\": 82377,\n   \"download_url\": \"https://example.com/file/download/-5x5lHOiT2Kc41ZfItJAAw?jwt=eyJhbGciOiJIUzI1NiJ9.eyJkaWciOiI5ZDE3NWFjMzkyM&mode=download\"\n  },\n  {\n   \"sender\": \"example_user@example.com\",\n   \"date_time\": \"2021-11-19T10:12:35Z\",\n   \"timestamp\": 1637316755220,\n   \"file_id\": \"-5x5lHOiT2Kc41ZfItJAAw\",\n   \"file_name\": \"example.png\",\n   \"file_size\": 82377,\n   \"download_url\": \"https://example.com/file/download/-5x5lHOiT2Kc41ZfItJAAw?jwt=eyJhbGciOiJIUzI1NiJ9.eyJkaWciOiI5ZDE3NWFjMz&mode=download\"\n  }\n ]\n}"
    },
    {
      "name": "**HTTP Status Code:** `400`<br> Bad request.<br>\n**Error Code:** `200`<br>Unauthorized request. You do not have permission to access this user's chat messages.<br>\n**Error Code:** `300` <br>The next page token is invalid or expired.<br>\n**Error Code:** `3",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit&date=1989-05-07&page_size=10&next_page_token=quis officia in reprehenderit&include_deleted_and_edited_message=quis officia in reprehenderit&search_type=message&search_key=quis nisi Duis ut",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages"
          ],
          "query": [
            {
              "key": "to_contact",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "to_channel",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "date",
              "value": "1989-05-07"
            },
            {
              "key": "page_size",
              "value": "10"
            },
            {
              "key": "next_page_token",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "include_deleted_and_edited_message",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "search_type",
              "value": "message"
            },
            {
              "key": "search_key",
              "value": "quis nisi Duis ut"
            }
          ],
          "variable": [
            {
              "key": "userId"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "**HTTP Status Code:** `404`<br>\n**Error Code**: `1001`<br>\nUser does not exist: $to_contact.<br>\n**Error Code**: `4130`<br>\nChannel does not exist: $to_channel.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit&date=1989-05-07&page_size=10&next_page_token=quis officia in reprehenderit&include_deleted_and_edited_message=quis officia in reprehenderit&search_type=message&search_key=quis nisi Duis ut",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages"
          ],
          "query": [
            {
              "key": "to_contact",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "to_channel",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "date",
              "value": "1989-05-07"
            },
            {
              "key": "page_size",
              "value": "10"
            },
            {
              "key": "next_page_token",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "include_deleted_and_edited_message",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "search_type",
              "value": "message"
            },
            {
              "key": "search_key",
              "value": "quis nisi Duis ut"
            }
          ],
          "variable": [
            {
              "key": "userId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}