Chilkat Online Tools

PureBasic / Support API / Search Users

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.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

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "login")
    CkHttp::setCkPassword(http, "password")

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"query","<string>")
    CkJsonObject::ckUpdateString(queryParams,"external_id","<string>")

    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/users/search",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)

    ; {
    ;   "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

    name.s
    active.s
    alias.s
    chat_only.s
    created_at.s
    custom_role_id.s
    default_group_id.s
    details.s
    email.s
    external_id.s
    iana_time_zone.s
    id.s
    last_login_at.s
    locale.s
    locale_id.s
    moderator.s
    notes.s
    only_private_comments.s
    organization_id.s
    phone.s
    In1f.i
    Cillumb5.i
    remote_photo_url.s
    report_csv.s
    restricted_agent.s
    role.s
    role_type.s
    v_shared.s
    shared_agent.s
    shared_phone_number.s
    signature.s
    suspended.s
    tags.s
    ticket_restriction.s
    time_zone.s
    two_factor_auth_enabled.s
    updated_at.s
    url.s
    Nisi_e.s
    verified.s
    Ut69.i
    Magna_4.i
    Loremcc.i
    Dolore7.i
    Pariaturf.s

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"users")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        name = CkJsonObject::ckStringOf(jResp,"users[i].name")
        active = CkJsonObject::ckStringOf(jResp,"users[i].active")
        alias = CkJsonObject::ckStringOf(jResp,"users[i].alias")
        chat_only = CkJsonObject::ckStringOf(jResp,"users[i].chat_only")
        created_at = CkJsonObject::ckStringOf(jResp,"users[i].created_at")
        custom_role_id = CkJsonObject::ckStringOf(jResp,"users[i].custom_role_id")
        default_group_id = CkJsonObject::ckStringOf(jResp,"users[i].default_group_id")
        details = CkJsonObject::ckStringOf(jResp,"users[i].details")
        email = CkJsonObject::ckStringOf(jResp,"users[i].email")
        external_id = CkJsonObject::ckStringOf(jResp,"users[i].external_id")
        iana_time_zone = CkJsonObject::ckStringOf(jResp,"users[i].iana_time_zone")
        id = CkJsonObject::ckStringOf(jResp,"users[i].id")
        last_login_at = CkJsonObject::ckStringOf(jResp,"users[i].last_login_at")
        locale = CkJsonObject::ckStringOf(jResp,"users[i].locale")
        locale_id = CkJsonObject::ckStringOf(jResp,"users[i].locale_id")
        moderator = CkJsonObject::ckStringOf(jResp,"users[i].moderator")
        notes = CkJsonObject::ckStringOf(jResp,"users[i].notes")
        only_private_comments = CkJsonObject::ckStringOf(jResp,"users[i].only_private_comments")
        organization_id = CkJsonObject::ckStringOf(jResp,"users[i].organization_id")
        phone = CkJsonObject::ckStringOf(jResp,"users[i].phone")
        In1f = CkJsonObject::ckBoolOf(jResp,"users[i].photo.in1f")
        Cillumb5 = CkJsonObject::ckBoolOf(jResp,"users[i].photo.cillumb5")
        remote_photo_url = CkJsonObject::ckStringOf(jResp,"users[i].remote_photo_url")
        report_csv = CkJsonObject::ckStringOf(jResp,"users[i].report_csv")
        restricted_agent = CkJsonObject::ckStringOf(jResp,"users[i].restricted_agent")
        role = CkJsonObject::ckStringOf(jResp,"users[i].role")
        role_type = CkJsonObject::ckStringOf(jResp,"users[i].role_type")
        v_shared = CkJsonObject::ckStringOf(jResp,"users[i].shared")
        shared_agent = CkJsonObject::ckStringOf(jResp,"users[i].shared_agent")
        shared_phone_number = CkJsonObject::ckStringOf(jResp,"users[i].shared_phone_number")
        signature = CkJsonObject::ckStringOf(jResp,"users[i].signature")
        suspended = CkJsonObject::ckStringOf(jResp,"users[i].suspended")
        tags = CkJsonObject::ckStringOf(jResp,"users[i].tags")
        ticket_restriction = CkJsonObject::ckStringOf(jResp,"users[i].ticket_restriction")
        time_zone = CkJsonObject::ckStringOf(jResp,"users[i].time_zone")
        two_factor_auth_enabled = CkJsonObject::ckStringOf(jResp,"users[i].two_factor_auth_enabled")
        updated_at = CkJsonObject::ckStringOf(jResp,"users[i].updated_at")
        url = CkJsonObject::ckStringOf(jResp,"users[i].url")
        Nisi_e = CkJsonObject::ckStringOf(jResp,"users[i].user_fields.nisi_e")
        verified = CkJsonObject::ckStringOf(jResp,"users[i].verified")
        Ut69 = CkJsonObject::ckBoolOf(jResp,"users[i].photo.ut69")
        Magna_4 = CkJsonObject::ckIntOf(jResp,"users[i].photo.magna_4")
        Loremcc = CkJsonObject::ckIntOf(jResp,"users[i].user_fields.Loremcc")
        Dolore7 = CkJsonObject::ckBoolOf(jResp,"users[i].user_fields.dolore7")
        Pariaturf = CkJsonObject::ckStringOf(jResp,"users[i].user_fields.pariaturf")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl  -u login:password -G -d "query=%3Cstring%3E"
	-d "external_id=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/users/search

Postman Collection Item JSON

{
  "name": "Search Users",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/users/search?query=<string>&external_id=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "users",
        "search"
      ],
      "query": [
        {
          "key": "query",
          "value": "<string>",
          "description": "The `query` parameter supports the Zendesk search syntax for more advanced\nuser searches. It can specify a partial or full value of any\nuser property, including name, email address, notes, or phone. Example:\n`query=\"jdoe\"`.\nSee the [Search API](/api-reference/ticketing/ticket-management/search/).\n"
        },
        {
          "key": "external_id",
          "value": "<string>",
          "description": "The `external_id` parameter does not support the search syntax. It only accepts ids.\n"
        }
      ]
    },
    "description": "Returns an array of users who meet the search criteria.\n\n#### Pagination\n\n* Offset pagination only\n\nSee [Using Offset Pagination](/api-reference/ticketing/introduction/#using-offset-pagination).\n\n#### Allowed For\n\n* Admins, Agents and Light 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/search?query=<string>&external_id=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "users",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "<string>",
              "description": "The `query` parameter supports the Zendesk search syntax for more advanced\nuser searches. It can specify a partial or full value of any\nuser property, including name, email address, notes, or phone. Example:\n`query=\"jdoe\"`.\nSee the [Search API](/api-reference/ticketing/ticket-management/search/).\n"
            },
            {
              "key": "external_id",
              "value": "<string>",
              "description": "The `external_id` parameter does not support the search syntax. It only accepts ids.\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}"
    }
  ]
}