Chilkat Online Tools

PureBasic / Zoom API / Get user’s IM 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,"chat_user","quis officia in reprehenderit")
    CkJsonObject::ckUpdateString(queryParams,"channel","quis officia in reprehenderit")
    CkJsonObject::ckUpdateString(queryParams,"date","quis officia in reprehenderit")
    CkJsonObject::ckUpdateInt(queryParams,"page_size",30)
    CkJsonObject::ckUpdateString(queryParams,"next_page_token","quis officia in reprehenderit")

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

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://api.zoom.us/v2/im/users/:userId/chat/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": "string [date]",
    ;   "page_size": "integer",
    ;   "next_page_token": "string",
    ;   "messages": [
    ;     {
    ;       "id": "string",
    ;       "message": "string",
    ;       "sender": "string",
    ;       "date_time": "string [date-time]",
    ;       "timstamp": "Long"
    ;     }
    ;   ]
    ; }

    ; 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
    timstamp.s

    date.s = CkJsonObject::ckStringOf(jResp,"date")
    page_size.s = CkJsonObject::ckStringOf(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)
        timstamp = CkJsonObject::ckStringOf(jResp,"messages[i].timstamp")
        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 "chat_user=quis%20officia%20in%20reprehenderit"
	-d "channel=quis%20officia%20in%20reprehenderit"
	-d "date=quis%20officia%20in%20reprehenderit"
	-d "page_size=30"
	-d "next_page_token=quis%20officia%20in%20reprehenderit"
	-H "Authorization: Bearer <access_token>"
https://api.zoom.us/v2/im/users/:userId/chat/messages

Postman Collection Item JSON

{
  "name": "Get user’s IM messages",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/im/users/:userId/chat/messages?chat_user=quis officia in reprehenderit&channel=quis officia in reprehenderit&date=quis officia in reprehenderit&page_size=30&next_page_token=quis officia in reprehenderit",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "im",
        "users",
        ":userId",
        "chat",
        "messages"
      ],
      "query": [
        {
          "key": "chat_user",
          "value": "quis officia in reprehenderit",
          "description": "Chat user's ID or email address."
        },
        {
          "key": "channel",
          "value": "quis officia in reprehenderit",
          "description": "IM Channel's ID."
        },
        {
          "key": "date",
          "value": "quis officia in reprehenderit",
          "description": "IM message's query date time, format as yyyy-MM-dd."
        },
        {
          "key": "page_size",
          "value": "30",
          "description": "The number of records returned within 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."
        }
      ],
      "variable": [
        {
          "key": "userId",
          "value": "quis officia in reprehenderit",
          "description": "(Required) The user ID or email address."
        }
      ]
    },
    "description": "Get IM Chat messages for a specified period of time. This API only supports Oauth2.<br>\n**Scopes:** `imchat:read`<br>\n**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`\n<br><br>\n  <p style=\"background-color:#e1f5fe; color:#000000; padding:8px\"><b>Deprecated:</b> By end of 2021, Zoom is deprecating this API in favor of a consolidated set of APIs. The API will still be available for you to use, though Zoom will no longer provide support for it. For further information, see <a href=\"https://marketplace.zoom.us/docs/guides/stay-up-to-date/announcements#im-api-notice\">Announcements: IM APIs Deprecation</a>.</p>\n"
  },
  "response": [
    {
      "name": "**HTTP Status Code:** `200`<br>\nUser's IM messages returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/im/users/:userId/chat/messages?chat_user=quis officia in reprehenderit&channel=quis officia in reprehenderit&date=quis officia in reprehenderit&page_size=30&next_page_token=quis officia in reprehenderit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "im",
            "users",
            ":userId",
            "chat",
            "messages"
          ],
          "query": [
            {
              "key": "chat_user",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "channel",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "date",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "page_size",
              "value": "30"
            },
            {
              "key": "next_page_token",
              "value": "quis officia in reprehenderit"
            }
          ],
          "variable": [
            {
              "key": "userId",
              "value": "quis officia in reprehenderit",
              "description": "(Required) The user ID or email address."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"date\": \"string [date]\",\n \"page_size\": \"integer\",\n \"next_page_token\": \"string\",\n \"messages\": [\n  {\n   \"id\": \"string\",\n   \"message\": \"string\",\n   \"sender\": \"string\",\n   \"date_time\": \"string [date-time]\",\n   \"timstamp\": \"Long\"\n  }\n ]\n}"
    }
  ]
}