Chilkat Online Tools

SQL Server / Zoom API / Search company contacts

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, 'search_key', 'quis officia in reprehenderit'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'query_presence_status', 'quis officia in reprehenderit'
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'page_size', 1
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'contact_types', 1
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'next_page_token', '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/contacts', @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)

    -- {
    --   "page_size": 1,
    --   "next_page_token": " ",
    --   "contacts": [
    --     {
    --       "id": "isds324bdfsf",
    --       "email": "example@example.com",
    --       "first_name": "John",
    --       "last_name": "Doe",
    --       "presence_status": "Offline",
    --       "phone_number": "15550100",
    --       "phone_numbers": [
    --         {
    --           "country": "US",
    --           "code": "+1",
    --           "number": "15550102",
    --           "verified": true,
    --           "label": "Mobile"
    --         }
    --       ],
    --       "sip_phone_number": "11111111",
    --       "direct_numbers": [
    --         111111,
    --         222222
    --       ],
    --       "extension_number": "010",
    --       "im_group_id": "fhksdhfew34hjds",
    --       "im_group_name": "Engineering",
    --       "dept": "Engineering",
    --       "job_title": "Engineer",
    --       "location": "New York",
    --       "sip_uri": "800@aaa.example.com",
    --       "contact_type": 1
    --     }
    --   ]
    -- }

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

    DECLARE @id nvarchar(4000)

    DECLARE @email nvarchar(4000)

    DECLARE @first_name nvarchar(4000)

    DECLARE @last_name nvarchar(4000)

    DECLARE @presence_status nvarchar(4000)

    DECLARE @phone_number nvarchar(4000)

    DECLARE @sip_phone_number nvarchar(4000)

    DECLARE @extension_number nvarchar(4000)

    DECLARE @im_group_id nvarchar(4000)

    DECLARE @im_group_name nvarchar(4000)

    DECLARE @dept nvarchar(4000)

    DECLARE @job_title nvarchar(4000)

    DECLARE @location nvarchar(4000)

    DECLARE @sip_uri nvarchar(4000)

    DECLARE @contact_type int

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @country nvarchar(4000)

    DECLARE @code nvarchar(4000)

    DECLARE @v_number nvarchar(4000)

    DECLARE @verified int

    DECLARE @label nvarchar(4000)

    DECLARE @intVal int

    DECLARE @page_size int
    EXEC sp_OAMethod @jResp, 'IntOf', @page_size OUT, 'page_size'
    DECLARE @next_page_token nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @next_page_token OUT, 'next_page_token'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'contacts'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'contacts[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'contacts[i].email'
        EXEC sp_OAMethod @jResp, 'StringOf', @first_name OUT, 'contacts[i].first_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @last_name OUT, 'contacts[i].last_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @presence_status OUT, 'contacts[i].presence_status'
        EXEC sp_OAMethod @jResp, 'StringOf', @phone_number OUT, 'contacts[i].phone_number'
        EXEC sp_OAMethod @jResp, 'StringOf', @sip_phone_number OUT, 'contacts[i].sip_phone_number'
        EXEC sp_OAMethod @jResp, 'StringOf', @extension_number OUT, 'contacts[i].extension_number'
        EXEC sp_OAMethod @jResp, 'StringOf', @im_group_id OUT, 'contacts[i].im_group_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @im_group_name OUT, 'contacts[i].im_group_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @dept OUT, 'contacts[i].dept'
        EXEC sp_OAMethod @jResp, 'StringOf', @job_title OUT, 'contacts[i].job_title'
        EXEC sp_OAMethod @jResp, 'StringOf', @location OUT, 'contacts[i].location'
        EXEC sp_OAMethod @jResp, 'StringOf', @sip_uri OUT, 'contacts[i].sip_uri'
        EXEC sp_OAMethod @jResp, 'IntOf', @contact_type OUT, 'contacts[i].contact_type'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'contacts[i].phone_numbers'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @country OUT, 'contacts[i].phone_numbers[j].country'
            EXEC sp_OAMethod @jResp, 'StringOf', @code OUT, 'contacts[i].phone_numbers[j].code'
            EXEC sp_OAMethod @jResp, 'StringOf', @v_number OUT, 'contacts[i].phone_numbers[j].number'
            EXEC sp_OAMethod @jResp, 'BoolOf', @verified OUT, 'contacts[i].phone_numbers[j].verified'
            EXEC sp_OAMethod @jResp, 'StringOf', @label OUT, 'contacts[i].phone_numbers[j].label'
            SELECT @j = @j + 1
          END
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'contacts[i].direct_numbers'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'IntOf', @intVal OUT, 'contacts[i].direct_numbers[j]'
            SELECT @j = @j + 1
          END
        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


END
GO

Curl Command

curl -G -d "search_key=quis%20officia%20in%20reprehenderit"
	-d "query_presence_status=quis%20officia%20in%20reprehenderit"
	-d "page_size=1"
	-d "contact_types=1"
	-d "next_page_token=quis%20officia%20in%20reprehenderit"
	-H "Authorization: Bearer <access_token>"
https://api.zoom.us/v2/contacts

Postman Collection Item JSON

{
  "name": "Search company contacts",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/contacts?search_key=quis officia in reprehenderit&query_presence_status=quis officia in reprehenderit&page_size=1&contact_types=1&next_page_token=quis officia in reprehenderit",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "contacts"
      ],
      "query": [
        {
          "key": "search_key",
          "value": "quis officia in reprehenderit",
          "description": "(Required) Provide the keyword - either first name, last name or email of the contact whom you have to search for."
        },
        {
          "key": "query_presence_status",
          "value": "quis officia in reprehenderit",
          "description": "Set `query_presence_status` to `true` in order to include the presence status of a contact in the response."
        },
        {
          "key": "page_size",
          "value": "1",
          "description": "The number of records to be returned with a single API call."
        },
        {
          "key": "contact_types",
          "value": "1",
          "description": "A comma-separated list of the type of user contact to query: \n* `1` — A Zoom user. \n* `2` — An auto receptionist. \n* `3` — A common area phone. \n* `4` — A call queue. \n * `5` — A shared line group. \n* `6` — A shared global directory. \n* `7` — A shared office contact. \n\n**Note:** \n* You must have a [phone management role with the \"**View**\" permission](https://support.zoom.us/hc/en-us/articles/360042099012-Using-Zoom-Phone-role-management) to query the `2`, `3`, `4`, `5`, and `7` values. \n* You must provide a valid `search_key` value to query this parameter."
        },
        {
          "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."
        }
      ]
    },
    "description": "A user under an organization's Zoom account has internal users listed under Company Contacts in the Zoom Client. Use this API to search users that are in the company contacts of a Zoom account. Using the `search_key` query parameter, provide either first name, last name or the email address of the user that you would like to search for. Optionally, set `query_presence_status` to `true` in order to include the presence status of a contact. <br><br>\n\n**Scopes:** `contact:read:admin`, `contact:read`<br>\n\n **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium` "
  },
  "response": [
    {
      "name": "**HTTP Status Code:** `200`<br>\nContact returned successfully.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: oauth2",
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/contacts?search_key=quis officia in reprehenderit&query_presence_status=quis officia in reprehenderit&page_size=1&contact_types=1&next_page_token=quis officia in reprehenderit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "contacts"
          ],
          "query": [
            {
              "key": "search_key",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "query_presence_status",
              "value": "quis officia in reprehenderit"
            },
            {
              "key": "page_size",
              "value": "1"
            },
            {
              "key": "contact_types",
              "value": "1"
            },
            {
              "key": "next_page_token",
              "value": "quis officia in reprehenderit"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"page_size\": 1,\n \"next_page_token\": \" \",\n \"contacts\": [\n  {\n   \"id\": \"isds324bdfsf\",\n   \"email\": \"example@example.com\",\n   \"first_name\": \"John\",\n   \"last_name\": \"Doe\",\n   \"presence_status\": \"Offline\",\n   \"phone_number\": \"15550100\",\n   \"phone_numbers\": [\n    {\n     \"country\": \"US\",\n     \"code\": \"+1\",\n     \"number\": \"15550102\",\n     \"verified\": true,\n     \"label\": \"Mobile\"\n    }\n   ],\n   \"sip_phone_number\": \"11111111\",\n   \"direct_numbers\": [\n    111111,\n    222222\n   ],\n   \"extension_number\": \"010\",\n   \"im_group_id\": \"fhksdhfew34hjds\",\n   \"im_group_name\": \"Engineering\",\n   \"dept\": \"Engineering\",\n   \"job_title\": \"Engineer\",\n   \"location\": \"New York\",\n   \"sip_uri\": \"800@aaa.example.com\",\n   \"contact_type\": 1\n  }\n ]\n}"
    }
  ]
}