PureBasic Zendesk: List Users

Back to Index

List users, returning a maximum of 100 users per page.

Documentation: https://developer.zendesk.com/rest_api/docs/core/users#list-users

CURL Command

curl https://subdomain.zendesk.com/api/v2/users.json \
  -u zendesk_email/token:zendesk_api_token

PureBasic Example

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

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

    success.i

    ;  URL: https://subdomain.zendesk.com/api/v2/users.json
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"subdomain.zendesk.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"zendesk_email/token","zendesk_api_token")

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

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/api/v2/users.json",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    respStatusCode.i = CkRest::ckResponseStatusCode(rest)
    If respStatusCode >= 400
        Debug "Response Status Code = " + Str(respStatusCode)
        Debug "Response Header:"
        Debug CkRest::ckResponseHeader(rest)
        Debug "Response Body:"
        Debug CkStringBuilder::ckGetAsString(sbResponseBody)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

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

    CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)

    next_page.s
    previous_page.s
    count.i
    i.i
    count_i.i
    id.i
    url.s
    name.s
    email.s
    created_at.s
    updated_at.s
    time_zone.s
    phone.s
    shared_phone_number.s
    photo.s
    locale_id.i
    locale.s
    organization_id.i
    role.s
    verified.i
    external_id.s
    alias.s
    active.i
    shared.i
    shared_agent.i
    last_login_at.s
    two_factor_auth_enabled.s
    signature.s
    details.s
    notes.s
    role_type.s
    custom_role_id.s
    moderator.i
    ticket_restriction.s
    only_private_comments.i
    restricted_agent.i
    suspended.i
    chat_only.i
    default_group_id.i
    photoUrl.s
    photoId.i
    photoFile_name.s
    photoContent_url.s
    photoMapped_content_url.s
    photoContent_type.s
    photoSize.i
    photoWidth.i
    photoHeight.i
    photoInline.i
    j.i
    count_j.i
    strVal.s
    file_name.s
    content_url.s
    mapped_content_url.s
    content_type.s
    size.i
    width.i
    height.i
    inline.i

    next_page = CkJsonObject::ckStringOf(jsonResponse,"next_page")
    previous_page = CkJsonObject::ckStringOf(jsonResponse,"previous_page")
    count = CkJsonObject::ckIntOf(jsonResponse,"count")
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jsonResponse,"users")
    While i < count_i
        CkJsonObject::setCkI(jsonResponse, i)
        id = CkJsonObject::ckIntOf(jsonResponse,"users[i].id")
        url = CkJsonObject::ckStringOf(jsonResponse,"users[i].url")
        name = CkJsonObject::ckStringOf(jsonResponse,"users[i].name")
        email = CkJsonObject::ckStringOf(jsonResponse,"users[i].email")
        created_at = CkJsonObject::ckStringOf(jsonResponse,"users[i].created_at")
        updated_at = CkJsonObject::ckStringOf(jsonResponse,"users[i].updated_at")
        time_zone = CkJsonObject::ckStringOf(jsonResponse,"users[i].time_zone")
        phone = CkJsonObject::ckStringOf(jsonResponse,"users[i].phone")
        shared_phone_number = CkJsonObject::ckStringOf(jsonResponse,"users[i].shared_phone_number")
        photo = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo")
        locale_id = CkJsonObject::ckIntOf(jsonResponse,"users[i].locale_id")
        locale = CkJsonObject::ckStringOf(jsonResponse,"users[i].locale")
        organization_id = CkJsonObject::ckIntOf(jsonResponse,"users[i].organization_id")
        role = CkJsonObject::ckStringOf(jsonResponse,"users[i].role")
        verified = CkJsonObject::ckBoolOf(jsonResponse,"users[i].verified")
        external_id = CkJsonObject::ckStringOf(jsonResponse,"users[i].external_id")
        alias = CkJsonObject::ckStringOf(jsonResponse,"users[i].alias")
        active = CkJsonObject::ckBoolOf(jsonResponse,"users[i].active")
        shared = CkJsonObject::ckBoolOf(jsonResponse,"users[i].shared")
        shared_agent = CkJsonObject::ckBoolOf(jsonResponse,"users[i].shared_agent")
        last_login_at = CkJsonObject::ckStringOf(jsonResponse,"users[i].last_login_at")
        two_factor_auth_enabled = CkJsonObject::ckStringOf(jsonResponse,"users[i].two_factor_auth_enabled")
        signature = CkJsonObject::ckStringOf(jsonResponse,"users[i].signature")
        details = CkJsonObject::ckStringOf(jsonResponse,"users[i].details")
        notes = CkJsonObject::ckStringOf(jsonResponse,"users[i].notes")
        role_type = CkJsonObject::ckStringOf(jsonResponse,"users[i].role_type")
        custom_role_id = CkJsonObject::ckStringOf(jsonResponse,"users[i].custom_role_id")
        moderator = CkJsonObject::ckBoolOf(jsonResponse,"users[i].moderator")
        ticket_restriction = CkJsonObject::ckStringOf(jsonResponse,"users[i].ticket_restriction")
        only_private_comments = CkJsonObject::ckBoolOf(jsonResponse,"users[i].only_private_comments")
        restricted_agent = CkJsonObject::ckBoolOf(jsonResponse,"users[i].restricted_agent")
        suspended = CkJsonObject::ckBoolOf(jsonResponse,"users[i].suspended")
        chat_only = CkJsonObject::ckBoolOf(jsonResponse,"users[i].chat_only")
        default_group_id = CkJsonObject::ckIntOf(jsonResponse,"users[i].default_group_id")
        photoUrl = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.url")
        photoId = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.id")
        photoFile_name = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.file_name")
        photoContent_url = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.content_url")
        photoMapped_content_url = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.mapped_content_url")
        photoContent_type = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.content_type")
        photoSize = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.size")
        photoWidth = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.width")
        photoHeight = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.height")
        photoInline = CkJsonObject::ckBoolOf(jsonResponse,"users[i].photo.inline")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"users[i].tags")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            strVal = CkJsonObject::ckStringOf(jsonResponse,"users[i].tags[j]")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jsonResponse,"users[i].photo.thumbnails")
        While j < count_j
            CkJsonObject::setCkJ(jsonResponse, j)
            url = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.thumbnails[j].url")
            id = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.thumbnails[j].id")
            file_name = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.thumbnails[j].file_name")
            content_url = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.thumbnails[j].content_url")
            mapped_content_url = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.thumbnails[j].mapped_content_url")
            content_type = CkJsonObject::ckStringOf(jsonResponse,"users[i].photo.thumbnails[j].content_type")
            size = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.thumbnails[j].size")
            width = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.thumbnails[j].width")
            height = CkJsonObject::ckIntOf(jsonResponse,"users[i].photo.thumbnails[j].height")
            inline = CkJsonObject::ckBoolOf(jsonResponse,"users[i].photo.thumbnails[j].inline")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkRest::ckDispose(rest)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

Sample JSON Response Body

{
  "users": [
    {
      "id": 361801727573,
      "url": "https://chilkat.zendesk.com/api/v2/users/361801727573.json",
      "name": "Matt Fausey",
      "email": "admin@chilkatsoft.com",
      "created_at": "2018-04-14T19:01:56Z",
      "updated_at": "2018-04-14T23:09:24Z",
      "time_zone": "Bogota",
      "phone": null,
      "shared_phone_number": null,
      "photo": null,
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": 360015071793,
      "role": "admin",
      "verified": true,
      "external_id": null,
      "tags": [
      ],
      "alias": null,
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": "2018-04-14T23:09:24Z",
      "two_factor_auth_enabled": null,
      "signature": null,
      "details": null,
      "notes": null,
      "role_type": null,
      "custom_role_id": null,
      "moderator": true,
      "ticket_restriction": null,
      "only_private_comments": false,
      "restricted_agent": false,
      "suspended": false,
      "chat_only": false,
      "default_group_id": 360000681553,
      "user_fields": {}
    },
    {
      "id": 361809055094,
      "url": "https://chilkat.zendesk.com/api/v2/users/361809055094.json",
      "name": "Sample customer",
      "email": "customer@example.com",
      "created_at": "2018-04-14T19:01:56Z",
      "updated_at": "2018-04-14T19:01:57Z",
      "time_zone": "Bogota",
      "phone": null,
      "shared_phone_number": null,
      "photo": {
        "url": "https://chilkat.zendesk.com/api/v2/attachments/360103279093.json",
        "id": 360103279093,
        "file_name": "profile_image_361809055094_2287229.jpg",
        "content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229.jpg",
        "mapped_content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229.jpg",
        "content_type": "image/jpeg",
        "size": 2587,
        "width": 40,
        "height": 40,
        "inline": false,
        "thumbnails": [
          {
            "url": "https://chilkat.zendesk.com/api/v2/attachments/360103279113.json",
            "id": 360103279113,
            "file_name": "profile_image_361809055094_2287229_thumb.jpg",
            "content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229_thumb.jpg",
            "mapped_content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229_thumb.jpg",
            "content_type": "image/jpeg",
            "size": 1980,
            "width": 32,
            "height": 32,
            "inline": false
          }
        ]
      },
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": null,
      "role": "end-user",
      "verified": false,
      "external_id": null,
      "tags": [
      ],
      "alias": null,
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": null,
      "two_factor_auth_enabled": false,
      "signature": null,
      "details": null,
      "notes": null,
      "role_type": null,
      "custom_role_id": null,
      "moderator": false,
      "ticket_restriction": "requested",
      "only_private_comments": false,
      "restricted_agent": true,
      "suspended": false,
      "chat_only": false,
      "default_group_id": null,
      "user_fields": {}
    },
    {
      "id": 361810194934,
      "url": "https://chilkat.zendesk.com/api/v2/users/361810194934.json",
      "name": "matt",
      "email": "matt@chilkat.io",
      "created_at": "2018-04-14T20:58:33Z",
      "updated_at": "2018-04-14T20:59:40Z",
      "time_zone": "Central Time (US & Canada)",
      "phone": null,
      "shared_phone_number": null,
      "photo": null,
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": 360015071793,
      "role": "end-user",
      "verified": false,
      "external_id": null,
      "tags": [
        "lizard",
        "gecko"
      ],
      "alias": "",
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": null,
      "two_factor_auth_enabled": false,
      "signature": null,
      "details": "",
      "notes": "Likes coffee",
      "role_type": null,
      "custom_role_id": null,
      "moderator": false,
      "ticket_restriction": "requested",
      "only_private_comments": false,
      "restricted_agent": true,
      "suspended": false,
      "chat_only": false,
      "default_group_id": null,
      "user_fields": {}
    },
    {
      "id": 361811376954,
      "url": "https://chilkat.zendesk.com/api/v2/users/361811376954.json",
      "name": "Roger Wilco",
      "email": "roger@chilkat.io",
      "created_at": "2018-04-14T23:09:24Z",
      "updated_at": "2018-04-14T23:09:24Z",
      "time_zone": "Bogota",
      "phone": null,
      "shared_phone_number": null,
      "photo": null,
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": null,
      "role": "end-user",
      "verified": false,
      "external_id": null,
      "tags": [
      ],
      "alias": null,
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": null,
      "two_factor_auth_enabled": false,
      "signature": null,
      "details": null,
      "notes": null,
      "role_type": null,
      "custom_role_id": null,
      "moderator": false,
      "ticket_restriction": "requested",
      "only_private_comments": false,
      "restricted_agent": true,
      "suspended": false,
      "chat_only": false,
      "default_group_id": null,
      "user_fields": {}
    }
  ],
  "next_page": null,
  "previous_page": null,
  "count": 4
}