Chilkat Online Tools

DataFlex / Zoom API / Send a chat message

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sId
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/v2/chat/users/:userId/messages"
    Set ComContentType Of hoReq To "multipart/form-data"
    Send ComAddParam To hoReq "message" "occaecat ipsum"

    Send ComAddParam To hoReq "to_contact" "occaecat ipsumamet ea deserunt eu"

    Send ComAddParam To hoReq "to_channel" "occaecat ipsumamet ea deserunt eunisi cillum aute ut"

    Send ComAddParam To hoReq "reply_main_message_id" "occaecat ipsumamet ea deserunt eunisi cillum aute uteu consequat cupidatat adipisicing"

    Send ComAddParam To hoReq "at_items" 'occaecat ipsumamet ea deserunt eunisi cillum aute uteu consequat cupidatat adipisicing[{"start_position":-22947248,"end_position":1617571,"at_type":2,"at_contact":"esse id eu tempor"},{"start_position":-10983967,"end_position":45505685,"at_type":2,"at_contact":"enim consectetur irure"}]'

    Send ComAddHeader To hoReq "Authorization" "Bearer <access_token>"

    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "api.zoom.us" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    // {
    //   "id": "ex35785hgdfjgt"
    // }

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

    Get ComStringOf Of hoJResp "id" To sId


End_Procedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: multipart/form-data"
	--form 'message=occaecat ipsum'
	--form 'to_contact=occaecat ipsumamet ea deserunt eu'
	--form 'to_channel=occaecat ipsumamet ea deserunt eunisi cillum aute ut'
	--form 'reply_main_message_id=occaecat ipsumamet ea deserunt eunisi cillum aute uteu consequat cupidatat adipisicing'
	--form 'at_items=occaecat ipsumamet ea deserunt eunisi cillum aute uteu consequat cupidatat adipisicing[{"start_position":-22947248,"end_position":1617571,"at_type":2,"at_contact":"esse id eu tempor"},{"start_position":-10983967,"end_position":45505685,"at_type":2,"at_contact":"enim consectetur irure"}]'
https://api.zoom.us/v2/chat/users/:userId/messages

Postman Collection Item JSON

{
  "name": "Send a chat message",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "multipart/form-data"
      }
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "message",
          "value": "occaecat ipsum",
          "description": "(Required) The message to be sent.",
          "type": "text"
        },
        {
          "key": "to_contact",
          "value": "amet ea deserunt eu",
          "description": "The email address of the contact to whom you would like to send the message.",
          "type": "text"
        },
        {
          "key": "to_channel",
          "value": "nisi cillum aute ut",
          "description": "The Channel Id of the channel where you would like to send a message.",
          "type": "text"
        },
        {
          "key": "reply_main_message_id",
          "value": "eu consequat cupidatat adipisicing",
          "description": "The reply message's ID. This field only returns if the message is a reply message.",
          "type": "text"
        },
        {
          "key": "at_items",
          "value": "[{\"start_position\":-22947248,\"end_position\":1617571,\"at_type\":2,\"at_contact\":\"esse id eu tempor\"},{\"start_position\":-10983967,\"end_position\":45505685,\"at_type\":2,\"at_contact\":\"enim consectetur irure\"}]",
          "description": "[Chat mentions](https://support.zoom.us/hc/en-us/articles/360037567431-Using-chat-mentions-and-slash-commands) object. Use this object to include mentions in the message that will be sent to  a channel. ",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{baseUrl}}/chat/users/:userId/messages",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "chat",
        "users",
        ":userId",
        "messages"
      ],
      "variable": [
        {
          "key": "userId"
        }
      ]
    },
    "description": "Send chat messages on Zoom to either an individual user who is in your contact list or to a [channel](https://support.zoom.us/hc/en-us/articles/200912909-Getting-Started-With-Channels-Group-Messaging-) of which you are a member. 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\nTo send a message to a contact, provide the contact's email address in the `to_contact` field. To send a message to a channel, provide the channel's ID in `to_channel` parameter\n\n**Scopes:** `chat_message:write`, `chat_message:write: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>, 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>Edit</b> permission for <b>Chat Messages</b>.</p>"
  },
  "response": [
    {
      "name": "**Status Code:** `201`<br>\nMessage sent.",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "message",
              "value": "aute exercitation",
              "description": "(Required) The message to be sent.",
              "type": "text"
            },
            {
              "key": "to_contact",
              "value": "qui occaecat",
              "description": "The email address of the contact to whom you would like to send the message.",
              "type": "text"
            },
            {
              "key": "to_channel",
              "value": "nulla ad officia eu",
              "description": "The Channel Id of the channel where you would like to send a message.",
              "type": "text"
            },
            {
              "key": "reply_main_message_id",
              "value": "cupida",
              "description": "The reply message's ID. This field only returns if the message is a reply message.",
              "type": "text"
            },
            {
              "key": "at_items",
              "value": "[{\"start_position\":-44996082,\"end_position\":-93325860,\"at_type\":2,\"at_contact\":\"dolore incididunt\"},{\"start_position\":6440971,\"end_position\":-42865372,\"at_type\":2,\"at_contact\":\"minim commodo\"}]",
              "description": "[Chat mentions](https://support.zoom.us/hc/en-us/articles/360037567431-Using-chat-mentions-and-slash-commands) object. Use this object to include mentions in the message that will be sent to  a channel. ",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages"
          ],
          "variable": [
            {
              "key": "userId"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"id\": \"ex35785hgdfjgt\"\n}"
    },
    {
      "name": "**HTTP Status Code:** `400`<br>\nBad request.<br>\n**Error Code:** `5301`<br>\nMessage sending failed.<br>\n**Error Code:** `5402`<br>\nThis only supports replies to a main message.",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "message",
              "value": "aute exercitation",
              "description": "(Required) The message to be sent.",
              "type": "text"
            },
            {
              "key": "to_contact",
              "value": "qui occaecat",
              "description": "The email address of the contact to whom you would like to send the message.",
              "type": "text"
            },
            {
              "key": "to_channel",
              "value": "nulla ad officia eu",
              "description": "The Channel Id of the channel where you would like to send a message.",
              "type": "text"
            },
            {
              "key": "reply_main_message_id",
              "value": "cupida",
              "description": "The reply message's ID. This field only returns if the message is a reply message.",
              "type": "text"
            },
            {
              "key": "at_items",
              "value": "[{\"start_position\":-44996082,\"end_position\":-93325860,\"at_type\":2,\"at_contact\":\"dolore incididunt\"},{\"start_position\":6440971,\"end_position\":-42865372,\"at_type\":2,\"at_contact\":\"minim commodo\"}]",
              "description": "[Chat mentions](https://support.zoom.us/hc/en-us/articles/360037567431-Using-chat-mentions-and-slash-commands) object. Use this object to include mentions in the message that will be sent to  a channel. ",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages"
          ],
          "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": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "message",
              "value": "aute exercitation",
              "description": "(Required) The message to be sent.",
              "type": "text"
            },
            {
              "key": "to_contact",
              "value": "qui occaecat",
              "description": "The email address of the contact to whom you would like to send the message.",
              "type": "text"
            },
            {
              "key": "to_channel",
              "value": "nulla ad officia eu",
              "description": "The Channel Id of the channel where you would like to send a message.",
              "type": "text"
            },
            {
              "key": "reply_main_message_id",
              "value": "cupida",
              "description": "The reply message's ID. This field only returns if the message is a reply message.",
              "type": "text"
            },
            {
              "key": "at_items",
              "value": "[{\"start_position\":-44996082,\"end_position\":-93325860,\"at_type\":2,\"at_contact\":\"dolore incididunt\"},{\"start_position\":6440971,\"end_position\":-42865372,\"at_type\":2,\"at_contact\":\"minim commodo\"}]",
              "description": "[Chat mentions](https://support.zoom.us/hc/en-us/articles/360037567431-Using-chat-mentions-and-slash-commands) object. Use this object to include mentions in the message that will be sent to  a channel. ",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{baseUrl}}/chat/users/:userId/messages",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "chat",
            "users",
            ":userId",
            "messages"
          ],
          "variable": [
            {
              "key": "userId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}