Chilkat Online Tools

SQL Server / Zoom API / Get a message

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'to_contact', 'quis officia in reprehenderit'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'to_channel', 'quis officia in reprehenderit'

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://api.zoom.us/v2/chat/users/:userId/messages/:messageId', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    -- {
    --   "id": "{4C6A11E6-0145-430F-BC4D-937886AE559D}",
    --   "message": "reply_file",
    --   "sender": "jemsa@example.com",
    --   "date_time": "2021-05-31T07:34:50Z",
    --   "timestamp": 1622446490991,
    --   "reply_main_message_id": "{52400403-DA96-4D7B-9E05-C1C399FF0725}",
    --   "reply_main_message_timestamp": 1622446481695,
    --   "reactions": [
    --     {
    --       "emoji": "U+ 00000023-0000fe0f",
    --       "total_count": 1
    --     }
    --   ]
    -- }

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

    DECLARE @date_time int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.DtObj', @date_time OUT

    DECLARE @emoji nvarchar(4000)

    DECLARE @total_count int

    DECLARE @id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
    DECLARE @message nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @message OUT, 'message'
    DECLARE @sender nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @sender OUT, 'sender'
    EXEC sp_OAMethod @jResp, 'DtOf', @success OUT, 'date_time', 0, @date_time
    DECLARE @timestamp int
    EXEC sp_OAMethod @jResp, 'IntOf', @timestamp OUT, 'timestamp'
    DECLARE @reply_main_message_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @reply_main_message_id OUT, 'reply_main_message_id'
    DECLARE @reply_main_message_timestamp int
    EXEC sp_OAMethod @jResp, 'IntOf', @reply_main_message_timestamp OUT, 'reply_main_message_timestamp'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'reactions'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @emoji OUT, 'reactions[i].emoji'
        EXEC sp_OAMethod @jResp, 'IntOf', @total_count OUT, 'reactions[i].total_count'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp
    EXEC @hr = sp_OADestroy @date_time


END
GO

Curl Command

curl -G -d "to_contact=quis%20officia%20in%20reprehenderit"
	-d "to_channel=quis%20officia%20in%20reprehenderit"
	-H "Authorization: Bearer <access_token>"
https://api.zoom.us/v2/chat/users/:userId/messages/:messageId

Postman Collection Item JSON

{
  "name": "Get a message",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/chat/users/:userId/messages/:messageId?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "chat",
        "users",
        ":userId",
        "messages",
        ":messageId"
      ],
      "query": [
        {
          "key": "to_contact",
          "value": "quis officia in reprehenderit",
          "description": "The `userId` or email address of a Zoom Chat contact to whom you sent the message.\\n\\n**Note:** You must use this query parameter to delete a message sent to a Zoom Chat contact. "
        },
        {
          "key": "to_channel",
          "value": "quis officia in reprehenderit",
          "description": "The `channelId` of the Zoom Chat channel where sent the message.\\n\\n**Note:** You must use this query parameter to delete a message sent to Zoom Chat channel."
        }
      ],
      "variable": [
        {
          "key": "messageId",
          "value": "quis officia in reprehenderit",
          "description": "(Required) Message ID"
        }
      ]
    },
    "description": "Get a chat message previously sent to a contact or a 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\nYou must provide one of the following query parameters:<br>\n* `to_contact` — The email address of the Zoom contact to whom you sent the message.\n* `to_channel` — The ID of the Zoom channel where you sent the message.\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`\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>, you can only use this API for a user assigned <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.\">the <b>Edit</b> permission for the <b>Chat message</b> role setting</a>.</p>"
  },
  "response": [
    {
      "name": "**HTTP Status Code:** `204`<br>\nGet message successfully.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages/:messageId?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages",
            ":messageId"
          ],
          "query": [
            {
              "key": "to_contact",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "to_channel",
              "value": "quis officia in reprehenderit"
            }
          ],
          "variable": [
            {
              "key": "messageId",
              "value": "quis officia in reprehenderit",
              "description": "(Required) Message ID"
            }
          ]
        }
      },
      "status": "No Content",
      "code": 204,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"id\": \"{4C6A11E6-0145-430F-BC4D-937886AE559D}\",\n \"message\": \"reply_file\",\n \"sender\": \"jemsa@example.com\",\n \"date_time\": \"2021-05-31T07:34:50Z\",\n \"timestamp\": 1622446490991,\n \"reply_main_message_id\": \"{52400403-DA96-4D7B-9E05-C1C399FF0725}\",\n \"reply_main_message_timestamp\": 1622446481695,\n \"reactions\": [\n  {\n   \"emoji\": \"U+ 00000023-0000fe0f\",\n   \"total_count\": 1\n  }\n ]\n}"
    },
    {
      "name": "**HTTP Status Code:** `400`<br>\nBad request.<br>\n**Error Code:** `200`<br>\nThe contact or the channel parameter provided is invalid.<br>\nOnly the sender of this message can get it.<br>\n**Error Code:** `300`<br>Channel does not exist: $messageId<br>Must pr",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages/:messageId?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages",
            ":messageId"
          ],
          "query": [
            {
              "key": "to_contact",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "to_channel",
              "value": "quis officia in reprehenderit"
            }
          ],
          "variable": [
            {
              "key": "messageId",
              "value": "quis officia in reprehenderit",
              "description": "(Required) Message ID"
            }
          ]
        }
      },
      "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/:messageId?to_contact=quis officia in reprehenderit&to_channel=quis officia in reprehenderit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages",
            ":messageId"
          ],
          "query": [
            {
              "key": "to_contact",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "to_channel",
              "value": "quis officia in reprehenderit"
            }
          ],
          "variable": [
            {
              "key": "messageId",
              "value": "quis officia in reprehenderit",
              "description": "(Required) Message ID"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}