Chilkat Online Tools

SQL Server / Support API / Autocomplete Users

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', 'login'
    EXEC sp_OASetProperty @http, 'Password', 'password'

    DECLARE @queryParams int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'name', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'field_id', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'source', '<string>'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://example.zendesk.com/api/v2/users/autocomplete', @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
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

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

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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)

    -- {
    --   "users": [
    --     {
    --       "name": "<string>",
    --       "active": "<boolean>",
    --       "alias": "<string>",
    --       "chat_only": "<boolean>",
    --       "created_at": "<string>",
    --       "custom_role_id": "<integer>",
    --       "default_group_id": "<integer>",
    --       "details": "<string>",
    --       "email": "<string>",
    --       "external_id": "<string>",
    --       "iana_time_zone": "<string>",
    --       "id": "<integer>",
    --       "last_login_at": "<string>",
    --       "locale": "<string>",
    --       "locale_id": "<integer>",
    --       "moderator": "<boolean>",
    --       "notes": "<string>",
    --       "only_private_comments": "<boolean>",
    --       "organization_id": "<integer>",
    --       "phone": "<string>",
    --       "photo": {
    --         "in1f": false,
    --         "cillumb5": true
    --       },
    --       "remote_photo_url": "<string>",
    --       "report_csv": "<boolean>",
    --       "restricted_agent": "<boolean>",
    --       "role": "<string>",
    --       "role_type": "<integer>",
    --       "shared": "<boolean>",
    --       "shared_agent": "<boolean>",
    --       "shared_phone_number": "<boolean>",
    --       "signature": "<string>",
    --       "suspended": "<boolean>",
    --       "tags": "<array>",
    --       "ticket_restriction": "<string>",
    --       "time_zone": "<string>",
    --       "two_factor_auth_enabled": "<boolean>",
    --       "updated_at": "<string>",
    --       "url": "<string>",
    --       "user_fields": {
    --         "nisi_e": "commodo exercitation consequat"
    --       },
    --       "verified": "<boolean>"
    --     },
    --     {
    --       "name": "<string>",
    --       "active": "<boolean>",
    --       "alias": "<string>",
    --       "chat_only": "<boolean>",
    --       "created_at": "<string>",
    --       "custom_role_id": "<integer>",
    --       "default_group_id": "<integer>",
    --       "details": "<string>",
    --       "email": "<string>",
    --       "external_id": "<string>",
    --       "iana_time_zone": "<string>",
    --       "id": "<integer>",
    --       "last_login_at": "<string>",
    --       "locale": "<string>",
    --       "locale_id": "<integer>",
    --       "moderator": "<boolean>",
    --       "notes": "<string>",
    --       "only_private_comments": "<boolean>",
    --       "organization_id": "<integer>",
    --       "phone": "<string>",
    --       "photo": {
    --         "ut69": true,
    --         "magna_4": -92520384
    --       },
    --       "remote_photo_url": "<string>",
    --       "report_csv": "<boolean>",
    --       "restricted_agent": "<boolean>",
    --       "role": "<string>",
    --       "role_type": "<integer>",
    --       "shared": "<boolean>",
    --       "shared_agent": "<boolean>",
    --       "shared_phone_number": "<boolean>",
    --       "signature": "<string>",
    --       "suspended": "<boolean>",
    --       "tags": "<array>",
    --       "ticket_restriction": "<string>",
    --       "time_zone": "<string>",
    --       "two_factor_auth_enabled": "<boolean>",
    --       "updated_at": "<string>",
    --       "url": "<string>",
    --       "user_fields": {
    --         "Loremcc": 52379422,
    --         "dolore7": true,
    --         "pariaturf": "magna consectet"
    --       },
    --       "verified": "<boolean>"
    --     }
    --   ]
    -- }

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

    DECLARE @name nvarchar(4000)

    DECLARE @active nvarchar(4000)

    DECLARE @alias nvarchar(4000)

    DECLARE @chat_only nvarchar(4000)

    DECLARE @created_at nvarchar(4000)

    DECLARE @custom_role_id nvarchar(4000)

    DECLARE @default_group_id nvarchar(4000)

    DECLARE @details nvarchar(4000)

    DECLARE @email nvarchar(4000)

    DECLARE @external_id nvarchar(4000)

    DECLARE @iana_time_zone nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @last_login_at nvarchar(4000)

    DECLARE @locale nvarchar(4000)

    DECLARE @locale_id nvarchar(4000)

    DECLARE @moderator nvarchar(4000)

    DECLARE @notes nvarchar(4000)

    DECLARE @only_private_comments nvarchar(4000)

    DECLARE @organization_id nvarchar(4000)

    DECLARE @phone nvarchar(4000)

    DECLARE @In1f int

    DECLARE @Cillumb5 int

    DECLARE @remote_photo_url nvarchar(4000)

    DECLARE @report_csv nvarchar(4000)

    DECLARE @restricted_agent nvarchar(4000)

    DECLARE @role nvarchar(4000)

    DECLARE @role_type nvarchar(4000)

    DECLARE @v_shared nvarchar(4000)

    DECLARE @shared_agent nvarchar(4000)

    DECLARE @shared_phone_number nvarchar(4000)

    DECLARE @signature nvarchar(4000)

    DECLARE @suspended nvarchar(4000)

    DECLARE @tags nvarchar(4000)

    DECLARE @ticket_restriction nvarchar(4000)

    DECLARE @time_zone nvarchar(4000)

    DECLARE @two_factor_auth_enabled nvarchar(4000)

    DECLARE @updated_at nvarchar(4000)

    DECLARE @url nvarchar(4000)

    DECLARE @Nisi_e nvarchar(4000)

    DECLARE @verified nvarchar(4000)

    DECLARE @Ut69 int

    DECLARE @Magna_4 int

    DECLARE @Loremcc int

    DECLARE @Dolore7 int

    DECLARE @Pariaturf nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'users'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'users[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @active OUT, 'users[i].active'
        EXEC sp_OAMethod @jResp, 'StringOf', @alias OUT, 'users[i].alias'
        EXEC sp_OAMethod @jResp, 'StringOf', @chat_only OUT, 'users[i].chat_only'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'users[i].created_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @custom_role_id OUT, 'users[i].custom_role_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @default_group_id OUT, 'users[i].default_group_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @details OUT, 'users[i].details'
        EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'users[i].email'
        EXEC sp_OAMethod @jResp, 'StringOf', @external_id OUT, 'users[i].external_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @iana_time_zone OUT, 'users[i].iana_time_zone'
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'users[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @last_login_at OUT, 'users[i].last_login_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @locale OUT, 'users[i].locale'
        EXEC sp_OAMethod @jResp, 'StringOf', @locale_id OUT, 'users[i].locale_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @moderator OUT, 'users[i].moderator'
        EXEC sp_OAMethod @jResp, 'StringOf', @notes OUT, 'users[i].notes'
        EXEC sp_OAMethod @jResp, 'StringOf', @only_private_comments OUT, 'users[i].only_private_comments'
        EXEC sp_OAMethod @jResp, 'StringOf', @organization_id OUT, 'users[i].organization_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @phone OUT, 'users[i].phone'
        EXEC sp_OAMethod @jResp, 'BoolOf', @In1f OUT, 'users[i].photo.in1f'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Cillumb5 OUT, 'users[i].photo.cillumb5'
        EXEC sp_OAMethod @jResp, 'StringOf', @remote_photo_url OUT, 'users[i].remote_photo_url'
        EXEC sp_OAMethod @jResp, 'StringOf', @report_csv OUT, 'users[i].report_csv'
        EXEC sp_OAMethod @jResp, 'StringOf', @restricted_agent OUT, 'users[i].restricted_agent'
        EXEC sp_OAMethod @jResp, 'StringOf', @role OUT, 'users[i].role'
        EXEC sp_OAMethod @jResp, 'StringOf', @role_type OUT, 'users[i].role_type'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_shared OUT, 'users[i].shared'
        EXEC sp_OAMethod @jResp, 'StringOf', @shared_agent OUT, 'users[i].shared_agent'
        EXEC sp_OAMethod @jResp, 'StringOf', @shared_phone_number OUT, 'users[i].shared_phone_number'
        EXEC sp_OAMethod @jResp, 'StringOf', @signature OUT, 'users[i].signature'
        EXEC sp_OAMethod @jResp, 'StringOf', @suspended OUT, 'users[i].suspended'
        EXEC sp_OAMethod @jResp, 'StringOf', @tags OUT, 'users[i].tags'
        EXEC sp_OAMethod @jResp, 'StringOf', @ticket_restriction OUT, 'users[i].ticket_restriction'
        EXEC sp_OAMethod @jResp, 'StringOf', @time_zone OUT, 'users[i].time_zone'
        EXEC sp_OAMethod @jResp, 'StringOf', @two_factor_auth_enabled OUT, 'users[i].two_factor_auth_enabled'
        EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'users[i].updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'users[i].url'
        EXEC sp_OAMethod @jResp, 'StringOf', @Nisi_e OUT, 'users[i].user_fields.nisi_e'
        EXEC sp_OAMethod @jResp, 'StringOf', @verified OUT, 'users[i].verified'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Ut69 OUT, 'users[i].photo.ut69'
        EXEC sp_OAMethod @jResp, 'IntOf', @Magna_4 OUT, 'users[i].photo.magna_4'
        EXEC sp_OAMethod @jResp, 'IntOf', @Loremcc OUT, 'users[i].user_fields.Loremcc'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Dolore7 OUT, 'users[i].user_fields.dolore7'
        EXEC sp_OAMethod @jResp, 'StringOf', @Pariaturf OUT, 'users[i].user_fields.pariaturf'
        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  -u login:password -G -d "name=%3Cstring%3E"
	-d "field_id=%3Cstring%3E"
	-d "source=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/users/autocomplete

Postman Collection Item JSON

{
  "name": "Autocomplete Users",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/users/autocomplete?name=<string>&field_id=<string>&source=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "users",
        "autocomplete"
      ],
      "query": [
        {
          "key": "name",
          "value": "<string>",
          "description": "(Required) The name to search for the user.\n"
        },
        {
          "key": "field_id",
          "value": "<string>",
          "description": "The id of a lookup relationship field.  The type of field is determined\nby the `source` param\n"
        },
        {
          "key": "source",
          "value": "<string>",
          "description": "If a `field_id` is provided, this specifies the type of the field.\nFor example, if the field is on a \"zen:user\", it references a field on a user\n"
        }
      ]
    },
    "description": "Returns an array of users whose name starts with the value specified in the `name` parameter.\nIt only returns users with no foreign identities.\n\n#### Allowed For\n\n* Agents\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/users/autocomplete?name=<string>&field_id=<string>&source=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "users",
            "autocomplete"
          ],
          "query": [
            {
              "key": "name",
              "value": "<string>",
              "description": "(Required) The name to search for the user.\n"
            },
            {
              "key": "field_id",
              "value": "<string>",
              "description": "The id of a lookup relationship field.  The type of field is determined\nby the `source` param\n"
            },
            {
              "key": "source",
              "value": "<string>",
              "description": "If a `field_id` is provided, this specifies the type of the field.\nFor example, if the field is on a \"zen:user\", it references a field on a user\n"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"users\": [\n    {\n      \"name\": \"<string>\",\n      \"active\": \"<boolean>\",\n      \"alias\": \"<string>\",\n      \"chat_only\": \"<boolean>\",\n      \"created_at\": \"<string>\",\n      \"custom_role_id\": \"<integer>\",\n      \"default_group_id\": \"<integer>\",\n      \"details\": \"<string>\",\n      \"email\": \"<string>\",\n      \"external_id\": \"<string>\",\n      \"iana_time_zone\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"last_login_at\": \"<string>\",\n      \"locale\": \"<string>\",\n      \"locale_id\": \"<integer>\",\n      \"moderator\": \"<boolean>\",\n      \"notes\": \"<string>\",\n      \"only_private_comments\": \"<boolean>\",\n      \"organization_id\": \"<integer>\",\n      \"phone\": \"<string>\",\n      \"photo\": {\n        \"in1f\": false,\n        \"cillumb5\": true\n      },\n      \"remote_photo_url\": \"<string>\",\n      \"report_csv\": \"<boolean>\",\n      \"restricted_agent\": \"<boolean>\",\n      \"role\": \"<string>\",\n      \"role_type\": \"<integer>\",\n      \"shared\": \"<boolean>\",\n      \"shared_agent\": \"<boolean>\",\n      \"shared_phone_number\": \"<boolean>\",\n      \"signature\": \"<string>\",\n      \"suspended\": \"<boolean>\",\n      \"tags\": \"<array>\",\n      \"ticket_restriction\": \"<string>\",\n      \"time_zone\": \"<string>\",\n      \"two_factor_auth_enabled\": \"<boolean>\",\n      \"updated_at\": \"<string>\",\n      \"url\": \"<string>\",\n      \"user_fields\": {\n        \"nisi_e\": \"commodo exercitation consequat\"\n      },\n      \"verified\": \"<boolean>\"\n    },\n    {\n      \"name\": \"<string>\",\n      \"active\": \"<boolean>\",\n      \"alias\": \"<string>\",\n      \"chat_only\": \"<boolean>\",\n      \"created_at\": \"<string>\",\n      \"custom_role_id\": \"<integer>\",\n      \"default_group_id\": \"<integer>\",\n      \"details\": \"<string>\",\n      \"email\": \"<string>\",\n      \"external_id\": \"<string>\",\n      \"iana_time_zone\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"last_login_at\": \"<string>\",\n      \"locale\": \"<string>\",\n      \"locale_id\": \"<integer>\",\n      \"moderator\": \"<boolean>\",\n      \"notes\": \"<string>\",\n      \"only_private_comments\": \"<boolean>\",\n      \"organization_id\": \"<integer>\",\n      \"phone\": \"<string>\",\n      \"photo\": {\n        \"ut69\": true,\n        \"magna_4\": -92520384\n      },\n      \"remote_photo_url\": \"<string>\",\n      \"report_csv\": \"<boolean>\",\n      \"restricted_agent\": \"<boolean>\",\n      \"role\": \"<string>\",\n      \"role_type\": \"<integer>\",\n      \"shared\": \"<boolean>\",\n      \"shared_agent\": \"<boolean>\",\n      \"shared_phone_number\": \"<boolean>\",\n      \"signature\": \"<string>\",\n      \"suspended\": \"<boolean>\",\n      \"tags\": \"<array>\",\n      \"ticket_restriction\": \"<string>\",\n      \"time_zone\": \"<string>\",\n      \"two_factor_auth_enabled\": \"<boolean>\",\n      \"updated_at\": \"<string>\",\n      \"url\": \"<string>\",\n      \"user_fields\": {\n        \"Loremcc\": 52379422,\n        \"dolore7\": true,\n        \"pariaturf\": \"magna consectet\"\n      },\n      \"verified\": \"<boolean>\"\n    }\n  ]\n}"
    }
  ]
}